private bool IsValidFile(string fileExtn)
{
string[] validFileTypes = { "bmp", "jpg", "png" };
bool isValidType = false;
for (int i = 0; i < validFileTypes.Length; i++)
{
if (fileExtn == "." + validFileTypes[i])
{
isValidType = true;
break;
}
}
return isValidType;
}
protected void b_submit_Click(object sender, EventArgs e)
{
HttpPostedFile myPostedFile = fileUpload.PostedFile;
if (myPostedFile != null && myPostedFile.ContentLength > 0)
{
FileInfo finfo = new FileInfo(myPostedFile.FileName);
string fileExtension = finfo.Extension.ToLower();
if (IsValidFile(fileExtension))
{
//Upload process
string virtualFolder = "~/uploaddocuments/";
string physicalFolder = Server.MapPath(virtualFolder);
fileUpload.SaveAs(physicalFolder + fileUpload.FileName);
}
else
{
//Invalid File Type
}
}
}
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.