.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Check to Validate Image format

Posted By:Lakhan Pal Garg       Posted Date: September 25, 2009    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  
 

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/

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend