HtmlInputFile during postback..

Discussion in 'ASP .Net Web Controls' started by newmem, Mar 29, 2005.

  1. newmem

    newmem Guest

    Hi

    In the webform, if a use selects a file to upload and submits the form. But
    if page validation fails, the HtmlInputFile loses the filename string and
    the user has to re-select the file using the browse button.

    Is there any way to persist the postedFile.filename during postback?

    Appreciate any help.
     
    newmem, Mar 29, 2005
    #1
    1. Advertising

  2. newmem

    Brock Allen Guest

    The value in a <input type=file> is not allowed to be set by the page. The
    browser always sets it to blank by default. This is for security, as malicious
    websites could seed the control with a path to sensitive data on your machine.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi
    >
    > In the webform, if a use selects a file to upload and submits the
    > form. But if page validation fails, the HtmlInputFile loses the
    > filename string and the user has to re-select the file using the
    > browse button.
    >
    > Is there any way to persist the postedFile.filename during postback?
    >
    > Appreciate any help.
    >
     
    Brock Allen, Mar 29, 2005
    #2
    1. Advertising

  3. Are you inserting the runat="server" attribute within the tag itself?



    "newmem" <""> wrote in message news:...
    > Hi
    >
    > In the webform, if a use selects a file to upload and submits the form.
    > But
    > if page validation fails, the HtmlInputFile loses the filename string and
    > the user has to re-select the file using the browse button.
    >
    > Is there any way to persist the postedFile.filename during postback?
    >
    > Appreciate any help.
    >
    >
    >
     
    Tampa.NET Koder, Mar 29, 2005
    #3
  4. newmem

    Alex Guest

    If you are having trouble with retrieving the name of the posted file, or
    the location to the posted file, make sure the form in which this control
    exists has the enctype="multipart/form-data" as seen below.

    <form id="DefaultForm" method="post" runat="server"
    enctype="multipart/form-data">
    </form>

    When you upload your picture, you should be able to access it in your code
    behind like this.

    HttpPostedFile file = Request.Files["MyFileUpload"];

    where the control is <INPUT name="MyFileUpload">

    Hopefully I answered the right question for you.
    --
    Alex Mueller
    "newmem" <""> wrote in message news:...
    > Hi
    >
    > In the webform, if a use selects a file to upload and submits the form.

    But
    > if page validation fails, the HtmlInputFile loses the filename string and
    > the user has to re-select the file using the browse button.
    >
    > Is there any way to persist the postedFile.filename during postback?
    >
    > Appreciate any help.
    >
    >
    >
     
    Alex, Mar 29, 2005
    #4
  5. newmem

    newmem Guest

    Can I use client-side validation ? would the browser retain the value in the
    <input type=file> control?


    "Brock Allen" <> wrote in message
    news:...
    > The value in a <input type=file> is not allowed to be set by the page. The
    > browser always sets it to blank by default. This is for security, as

    malicious
    > websites could seed the control with a path to sensitive data on your

    machine.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hi
    > >
    > > In the webform, if a use selects a file to upload and submits the
    > > form. But if page validation fails, the HtmlInputFile loses the
    > > filename string and the user has to re-select the file using the
    > > browse button.
    > >
    > > Is there any way to persist the postedFile.filename during postback?
    > >
    > > Appreciate any help.
    > >

    >
    >
    >
     
    newmem, Mar 29, 2005
    #5
  6. newmem

    Brock Allen Guest

    I've not tried too hard to make this work, but I don't even think client
    side script allows you to set the value of the file input. Again, it's a
    security risk, so hopefully this won't work for you. Sorry. ;)

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Can I use client-side validation ? would the browser retain the value
    > in the <input type=file> control?
    >
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> The value in a <input type=file> is not allowed to be set by the
    >> page. The browser always sets it to blank by default. This is for
    >> security, as
    >>

    > malicious
    >
    >> websites could seed the control with a path to sensitive data on your
    >>

    > machine.
    >
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> Hi
    >>>
    >>> In the webform, if a use selects a file to upload and submits the
    >>> form. But if page validation fails, the HtmlInputFile loses the
    >>> filename string and the user has to re-select the file using the
    >>> browse button.
    >>>
    >>> Is there any way to persist the postedFile.filename during postback?
    >>>
    >>> Appreciate any help.
    >>>
     
    Brock Allen, Mar 29, 2005
    #6
    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. Dave Adler
    Replies:
    3
    Views:
    3,066
    bruce barker
    Feb 18, 2004
  2. bruce barker
    Replies:
    0
    Views:
    917
    bruce barker
    Aug 4, 2004
  3. newmem

    HtmlInputFile during postback..

    newmem, Mar 29, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    2,109
    Brock Allen
    Mar 29, 2005
  4. traveller
    Replies:
    0
    Views:
    1,193
    traveller
    Jan 8, 2008
  5. Jeff Richardson

    HtmlInputFile control and Postback

    Jeff Richardson, Oct 1, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    131
    Jeff Richardson
    Oct 1, 2003
Loading...

Share This Page