Reputation: 51
How to Upload only images in asp.net(FileUploadControl) not only followed by Extension validation because i found when Change the extension of any file with .jpg/.png it uploaded.
Upvotes: 0
Views: 4413
Reputation:
use ajax file upload..!! then save the file name in the database..!!
could get the extension "System.IO.Path.GetExtension(AsyncFileUpload1.PostedFile.FileName)"
refer this link..!!
http://www.aspsnippets.com/Articles/Using-ASP.Net-AJAX-Control-Toolkits-AsyncFileUpload-Control.aspx
Upvotes: 0
Reputation: 2210
Here's a prototype code that you can use
if (FileUpload1.HasFile)
{
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".jpg")
{
FileUpload1.SaveAs("yourpath" + FileUpload1.FileName);
}
else
{
Response.Write("Only .Jpg allowed");
}
}
You can add .PNG,.bmp also.. if u want
Upvotes: 1