Check to Validate Image format

Lakhangarg
Posted by Lakhangarg under C# category on | Views : 2631
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;

public 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;
}
}


Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/

Comments or Responses

Login to post response