Code
Protected void button#click (object sender, EventArgs e)
{
String fileName = this. File1.PostedFile. FileName; // get the client file name
String type = fileName. Substring (fileName. LastIndexOf (".") + 1). ToLower (); // get the file suffix
If (type = "jpg" | type = "gif" | type = "jpeg") // determine the file format
{
String savePath = Server. MapPath ("~ /Upload/"); // specifies the storage path of the uploaded file on the server.
If (! Directory. Exists (savePath) // check whether the physical path Exists on the server.
{
Directory. CreateDirectory (savePath); // create a Directory if it does not exist
}
This. File1.PostedFile. SaveAs (savePath + "\" + fileName); // upload
This. Image1.ImageUrl = "Image/" + filename; // The Image is displayed after the upload is successful.
}
Else
{
Response. Write ("<Script language = 'javascript '> alert ('format error') </Script> ");
}
}