if(IsPostBack)
{
Boolean fileOK=false;
String fileExtention=System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); //check file extension
Response.Write(Extension is..."+fileExtension);
String[] allowedExtension={".gif",".png"}; //only two file extension are accepted
for(int i=0;i<allowedExtension.Length;i++)
{
if(fileExtention==allowedExtension[i]) //check both extension are same
{
fileOK=true;
}}}
if(fileOK)
{try{FileUpload.PostedFile.SaveAs(path+FileUpload1.FileName);
Label1.Text="FileUploaded!";
}
catch(Exception ex)
{
Label1.Text="File could not be uploaded";
}}
else
{
Label1.Text="cannot accept files of this type";
}
}
}