Check to Validate Image format

Lakhangarg
Posted by Lakhangarg under C# category on | Views : 4172
Pass The FileUploadControl ID as Ref Parameter.
This Function will return true if the file format will be gif,jpeg,pjpeg,png,jpg or bmp otherwise it will return false;

static bool CheckValidImageFormat(ref FileUpload file)
{
if (file.PostedFile.ContentType.ToLower() == "image/gif" || file.PostedFile.ContentType.ToLower () == "image/jpeg" || file.PostedFile.ContentType.ToLower() == "image/pjpeg" || file.PostedFile.ContentType.ToLower () == "image/x-png" || file.PostedFile.ContentType.ToLower() == "image/jpg" || file.PostedFile.ContentType.ToLower () == "image/bmp")
{
return true;
}
else
{
return false;
}
}

Comments or Responses

Login to post response