The Architecture Journal Lastest issue is avaliable, you can download it from here
Favorites
Most Wanted Regular Expressions
Just wanted to share this little collection of “Most Wanted Regular Expressions”
Regular expression examples for decimals input
Positive Integers — ^d+$
Negative Integers — ^-d+$
Integer — ^-{0,1}d+$
Positive Number — ^d*.{0,1}d+$
Negative Number — ^-d*.{0,1}d+$
Positive Number or Negative Number – ^-{0,1}d*.{0,1}d+$
Phone number — ^+?[ds]{3,}$
Phone with code — ^+?[ds]+(?[ds]{10,}$
Year 1900-2099 — ^(19|20)[d]{2,2}$
Date (dd mm yyyy, d/m/yyyy, etc.) — ^([1-9]|0[1-9]|[12][1-9]|3[01])D([1-9]|0[1-9]|1[012])D(19[0-9][0-9]|20[0-9][0-9])$
IP v4 — ^(d|[1-9]d|1dd|2[0-4]d|25[0-5]).(d|[1-9]d|1dd|2[0-4]d|25[0-5]){3}$
Regular expression examples for Alphabetic input
Personal Name — ^[w.’]{2,}([s][w.’]{2,})+$
Username — ^[wd_.]{4,}$
Password at least 6 symbols — ^.{6,}$
Password or empty input — ^.{6,}$|^$
email — ^[_]*([a-z0-9]+(.|_*)?)+@([a-z][a-z0-9-]+(.|-*.))+[a-z]{2,6}$
domain — ^([a-z][a-z0-9-]+(.|-*.))+[a-z]{2,6}$
Url — http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
Other regular expressions
Match no input — ^$
Match blank input — ^s[t]*$
Match New line — [rn]|$
Common Table Expression
There’s a good article here by Frank Kerrigan on a way to implement paging in SQL Server 2005 by using Common Table Expressions (CTE’s).
What are CTE’s? This is a new feature of SQL Server 2005 that helps you eliminate temp tables and cursors in your queries. You can generate some pretty amazing queries using recursive CTE’s, but that’s not what Frank is trying to demonstrate. Anyway, they can be used similarly to a derived table.
Here’s the syntax:
[ WITH <common_table_expression> [ ,...n ] ] <common_table_expression>::= expression_name [ ( column_name [ ,...n ] ) ] AS ( CTE_query_definition )
Code to upload file in c#
protected void btnUploadFile_Click(object sender, EventArgs e){
string sFilename = “”;// Check file size (mustn’t be 0)
HttpPostedFile myFile = FileUploading.PostedFile;int nFileLen = myFile.ContentLength;
if (nFileLen==0){
lblMsg.Text=“No valid file for upload.”;// return;
}
else
{
byte[] myData=new Byte[nFileLen];myFile.InputStream.Read(myData, 0, nFileLen);
sFilename=System.Guid.NewGuid().ToString().Replace(“-“, “”)+“_”+System.IO.Path.GetFileName(myFile.FileName);// Save the stream to disk
System.IO.FileStream newFile=new System.IO.FileStream(Server.MapPath(TaskManagementTool.Config.Path+sFilename), System.IO.FileMode.Create);newFile.Write(myData, 0, myData.Length);
newFile.Close();
TaskManagementTool.TaskDB taskDB=new TaskManagementTool.TaskDB();taskDB.AddUploadedFile(Convert.ToInt32(lblTaskId.Text), sFilename, ckIsPrivate.Checked);ShowUploadFiles();
}
// Read file into a data stream
//return sFilename;
}
Place Cursor in the First Input Box Automatically
protected void Page_Load(object sender, EventArgs e)
{ FindFirstTextBox(this); }
private bool FindFirstTextBox(Control ctl)
{ bool foundControl = false;
foreach (Control child in ctl.Controls)
{
if (child is TextBox)
{
System.Text.StringBuilder script = new System.Text.StringBuilder();
script.AppendFormat("function findFirstControl()n{1}n document.getElementById("{0}").focus();n{2}n", child.ID, "{", "}");
ClientScript.RegisterClientScriptBlock(this.GetType(),"findFirstControl", script.ToString(), true);
foundControl = true;
break;
}
if (FindFirstTextBox(child))
{
foundControl = true;
break;
}
}
return foundControl;
}
Url Vaildator in asp.net
buddy here is regular expression for Url Vaildation
“http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?”
asp.net control would be look like
<asp:RegularExpressionValidator ID=”RegularExpressionValidator1″ ControlToValidate=”XYZl” ValidationExpression=”http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?” runat=”server” ErrorMessage=”Invalid URL”></asp:RegularExpressionValidator>
enjoy
how to download file in .net
Function DownloadFile(ByVal strFileName As String)Dim fs As FileStreamDim strContentType As String
Dim strPath = ConfigurationSettings.AppSettings(“DocumentsContainerLocal”)‘Dim strFileName As String = Request.QueryString(“DocumentFile”)
fs = File.Open(strPath & strFileName, FileMode.Open)
Dim bytBytes(fs.Length) As Byte
‘ Write the stream to the byte array
fs.Read(bytBytes, 0, fs.Length)
‘ Close the file stream to release the resource
fs.Close()
Response.AddHeader(“Content-disposition”, _
“attachment; filename=” & strFileName)
‘ Next we need to add some header information.
‘ These headers will tell the browser what it needs to do
‘ with the content we’re serving
Response.ContentType = “application/octet-stream”
‘ Now our headers are added, we can serve the content.
‘ To do this, we use the BinaryWrite() method of the server object
‘ This successfully streams our external file to the user,
‘ despite the fact that the file doesn’t exist
‘ anywhere inside the web application
Response.BinaryWrite(bytBytes)
‘ Call Response.End() so that no more
‘ content goes through to the client.
Response.End()
End Function
Who invented “CTRL + ALT + DEL ” key combination
Have you ever thought of the person who invented “CTRL + ALT + DEL ” key combination. “David Bradley” He is the One who spent 1 minute and 23 seconds in writing the source code that rescues The world’s PC users for decades This extraordinary IBM employee is retiring on Friday, 25th March 2005 after a prolong service of 29 years. His formula forces obstinate computers to restart when they no longer follow other commands. By 1980, Bradley was one of 12 people working to create the debut. The engineers knew they had to design a simple way to restart the computer When it fails to respond the user Bradley wrote the code to make it work. Bradley says. “I did a lot of other things than Ctrl-Alt-Delete, but I’m famous for that one.” His fame and success is achieved each time a PC user fails. He Commented His relationship with Bill gates by saying “I may have invented it, but Bill gates made it famous by applying my formula When ever any Microsoft’s Windows operating system made by him CRASHES, Thus I win when ever he looses………..”
Window Live
got an invitation from Hotmail to try Hotmail Beta Live and without wasting a single moment I jumped into the site, accepted the invitation and sign in to see the new Hotmail. First it took a while to load all the scripts to provide client side processing functionality. Hotmail live will give you feeling that you are working inside Outlook. Resize columns, Spell check, move between folders and download mails without refreshing the page all the time. According to them, Hotmail Live will take over current Homail within few weeks, and hopefully everyone will be repeaing the benefits from the new exciting services. The sad part is, it does not provide all AJAX functionalities with browsers other then IE. However, Hotmail team will provide all the features for all browsers before the final release. This is how Homail Live looks like:
Why Use Forms Authentication?
No of reasons that mostly developers use Form based authentication in their asp.net application
- They have full control over the authentication code.
- They have full control over the appearance of the login form.
- Form based authentication works with any browser.
- Form based authentication allows developer how to store user information.
-
Developer have to create the user interface for users to log in.
-
Developers have to maintain a catalog with user credentials.
-
Developers have to take additional precautions against the interception of network traffic
Form Based authentication has some drawbacks as well.