Forum Moderators: open

Message Too Old, No Replies

File upload form

         

morpheus83

8:08 am on Jan 15, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



I want to create a form in c# which allows users to upload files. However I want to limit users to upload files limited to a pre defined extension. For eg - The form to allow users to only upload .jpg files . Can anyone please post the code or guide me regarding this, I am a newbie to c# I searched on google for tis but could not find a script which would allow me to limit the upload by extension.
Thanks in advance

txbakers

2:44 pm on Jan 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there is a component called aspupload (search for it) which has built in code to handle all sorts of event, including allowing only certain extensions.

I've been using it for quite some time now.

tomasz

4:32 pm on Jan 15, 2005 (gmt 0)

10+ Year Member



in Vb.net you can use ContentType of posted file.
bellow example only allows IMAGE type files BMP, JPG, GIF

Protected WithEvents ImageUpload As System.Web.UI.HtmlControls.HtmlInputFile
.....

Dim sImgType As String = ImageUpload.PostedFile.ContentType.ToString
If Left(UCase(sImgType), 5) = "IMAGE" Then
....

you can be more speciffic with
ImageUpload.PostedFile.FileName.ToString

//to do // c# syntax is very similar

raptorix

4:14 pm on Jan 16, 2005 (gmt 0)

10+ Year Member



As said above, check on mimetype NOT on extension, checking only on extension can cause security problems (think about viruses).