Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict File Type for Upload File

Status
Not open for further replies.

suicidaltendencies

Programmer
Jan 28, 2004
58
US
I'm using the HtmlInputFile control to upload a image file. I only want to allow the user to upload jpg or jpeg extensions. How do I do limit them to those type of files?

Thanks,
Harold
 
You can get the fully qualified filename (eg. "C:/test.txt") of the uploaded file using

HtmlInputFile1.PostedFile.FileName

A bit of string manipulation will get you the extension easy enough. However, you can get the content type (eg. "image/jpeg") using

HtmlInputFile1.PostedFile.ContentType

This will let you kno the type of the file being uploaded not just extension. That way even if the file has the wrong extension but is a jpg you can still use it or if it is right extension but not really jpg you will spot that as well.

Hope this helps

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
I'm trying to limit the user through the use of the dialog box that is shown when you click browse.

Can you help?
 
Same problem I got....

The dialog box shows "All Files" ... Can you force the dialog box to show only jpg or bmp? besides checking the content type later?
 
MSDN says to use
Code:
<form enctype="multipart/form-data">
...
<input type="file" accept="content_type">
...
</form>
where "content_type", in your case, should be: "image/jpeg".

The problem is that it doesn't seem to work ... :(

[morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top