You can try that in the Following way.
if (fileUploadCategoryImage.HasFile == true)
{
categoryImageName = fn_UploadCategoryImage(fileUploadCategoryImage);
}
public string fn_UploadCategoryImage(FileUpload UploadedFile)
{
HttpPostedFile file = UploadedFile.PostedFile;
string fileExt = Path.GetExtension(file.FileName).ToLower();
string fileName = Path.GetFileName(file.FileName);
if (fileName != string.Empty)
{
try
{
if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
{
str = DateTime.Now.ToFileTime() + "_" + fileName;
file.SaveAs(Server.MapPath("~/admin/Upload/Category/") + str);
}
}
catch (Exception ex)
{
throw ex;
}
}
return str;
}