-
07-27-2010, 11:40 AM #1
- Join Date
- Apr 2008
- Location
- Boston, USA
- Posts
- 13,122
- Thanks
- 742
- Thanked 674 Times in 543 Posts
- Blog Entries
- 4
- Feedback Score
- 4 (100%)
How to Check Uploaded File Extension - ASP .Net
How to Check Uploaded File Extension - ASP .Net
If you have fileUpload as your upload control
<input id="fileUpload" type="file" runat="server" />
This code sample check the file type if its an image. It can be altered for other file types as well. This example code is in C#.
HttpPostedFile myPostedFile=fileUpload.PostedFile;
if(myPostedFile!=null && myPostedFile.ContentLength>0)
{
FileInfo finfo = new FileInfo(myPostedFile.FileName);
string fileExtension = finfo.Extension.ToLower();
if (fileExtension != ".gif" && fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".png")
{
//show error message
return;
}
}
Similar Threads
-
Brand New TLD .xxx extension extension got approval from ICANN
By soney218 in forum Domain NamesReplies: 0Last Post: 06-28-2010, 06:45 AM -
Preference in SEO terms for URL file extension?
By glenbolton85 in forum Search Engine OptimizationReplies: 3Last Post: 06-28-2010, 02:44 AM -
My keywords are not uploaded.
By salman in forum Microsoft AdCenterReplies: 3Last Post: 01-08-2010, 02:05 AM -
How to find a pdf file is normal file or shared review file
By sunshine in forum JavaScript & AJAXReplies: 0Last Post: 01-04-2010, 12:21 PM -
Cannot load mcrypt extension. Please check your PHP configuration
By manik in forum PHPReplies: 0Last Post: 08-30-2008, 09:24 PM


Reply With Quote

