Change "File of Type" in the Browse File dialog box.

J

Jen

Hi all,

I was wondering if it is possible to change or default the type of file the "Browse File" dialog box. Coz' I want to limit the type of files my user can upload.

Thanks.

Regards,
Jen
 
A

Alessandro Zifiglio

when using the HtmlInputFile control check its postedFile propertys
ContentType attribute. Check this against a predefined set of values, and if
the check pases then upload the file to the server otherwise display an
error to the user stating the file type is not supported etc ;P


if File1.PostedFile.ContentType = "US-ASCII" then
'take action
end if

Jen said:
Hi all,

I was wondering if it is possible to change or default the type of file
the "Browse File" dialog box. Coz' I want to limit the type of files my
user can upload.
 
A

Alessandro Zifiglio

oops, this is not what you asked for. Yes you can limit the files in the
file open dialogbox.

here try this :

Public Class MyUrlEditor : Inherits FileNameEditor
Protected Overrides Sub InitializeDialog(ByVal openFileDialog As
OpenFileDialog)
openFileDialog.Filter =
"(*.JPG;*.JPEG;*.GIF;*.PNG)|*.JPG;*.JPEG;*.GIF;*.PNG|All files (*.*)|*.*"
End Sub
 
J

Jen

Hi Alessandro,

Thank you for your help. But I am a newbie in aspnet and C#. Pardon me, if I sound silly.
First of all, my development environment is asp.net for web. The codes you provide me with seems to be meant for window base (I really don't know how to apply it). Therefore, I didn't manage to get it working. I am using "file field" with the default "browse" button.

Regards,
Je
 
A

Alessandro Zifiglio

Jen, much clearer now. You cannot control through server side code, you can
check what files are being uploaded and limit option to disallow this with
an error message showing wrong file name. But this is not what you want.
What your saying is you want to filter out file types for you input file
element. This is possible by using the accept attribute for your input file
element and supplying it a list of files you want to accept.
Sample :
<input type="file" name="uploaded_file" accept="image/png, image/gif" />

Examples of content types include "text/html", "image/png", "image/gif",
"video/mpeg", "audio/basic", "text/tcl", "text/javascript", and
"text/vbscript". For the current list of registered Multipurpose Internet
Mail Extensions (MIME) types, see
http://www.w3.org/TR/1998/REC-html40-19980424/references.html#ref-MIMETYPES

On a side note : Always use the enctype of "multi-part/form-data" on the
form, otherwise the files will not upload correctly

Jen said:
Hi Alessandro,

Thank you for your help. But I am a newbie in aspnet and C#. Pardon me, if I sound silly.
First of all, my development environment is asp.net for web. The codes
you provide me with seems to be meant for window base (I really don't know
how to apply it). Therefore, I didn't manage to get it working. I am using
"file field" with the default "browse" button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top