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

Discussion in 'ASP .Net Web Controls' started by Jen, Feb 6, 2004.

  1. Jen

    Jen Guest

    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
     
    Jen, Feb 6, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Alessandro Zifiglio, Feb 6, 2004
    #2
    1. Advertising

  3. 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

    "Alessandro Zifiglio" <> wrote in
    message news:WRMUb.4187$...
    > 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" <> wrote in message
    > news:...
    > > 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

    >
    >
     
    Alessandro Zifiglio, Feb 6, 2004
    #3
  4. Jen

    Jen Guest

    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
     
    Jen, Feb 12, 2004
    #4
  5. 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" <> wrote in message
    news:...
    > 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,
    > Jen
    >
    >
     
    Alessandro Zifiglio, Feb 12, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anita C

    Browse File dialog

    Anita C, Nov 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,929
    Anita C
    Dec 1, 2003
  2. FlashT

    Browse file dialog box...

    FlashT, Apr 8, 2005, in forum: HTML
    Replies:
    1
    Views:
    711
    David Dorward
    Apr 9, 2005
  3. =?Utf-8?B?ZGVuIDIwMDU=?=

    Getting File Path in Browse File Dialog in ASP.Net

    =?Utf-8?B?ZGVuIDIwMDU=?=, May 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    10,607
    =?Utf-8?B?ZGVuIDIwMDU=?=
    May 8, 2006
  4. Highlander
    Replies:
    3
    Views:
    8,329
    Walter Zackery
    Aug 30, 2006
  5. Replies:
    0
    Views:
    223
Loading...

Share This Page