<input type="file"

Discussion in 'ASP .Net Web Controls' started by Pai, Aug 29, 2003.

  1. Pai

    Pai Guest

    Hello there,

    Good Morning,

    I am facing a peculiar problem.

    I have the following code in the html section of my .apsx page

    <input type="file" runat="server" id="fileBrowse" NAME="fileBrowse">

    and the following code in my code behin:

    string srcUrl = System.IO.Path.GetFullPath(fileBrowse.PostedFile.FileName);
    string srcFileName =
    System.IO.Path.GetFileName(fileBrowse.PostedFile.FileName);

    Stream fStream = fileBrowse.PostedFile.InputStream;
    byte[] contents = new byte[fStream.Length];
    fStream.Read(contents, 0, (int)fStream.Length);
    fStream.Close();

    I also have another server side control whcih is a button

    <asp:button id="AddUser" runat="server" Text="test">

    when I click on this button and then try to upload the file, the
    reference to the file which has to be uploaded is lost....

    and fileBrowse.PostedFile.FileName holds value = ""....

    I am not able to figure out how to go about this....

    any idea why this is happening....

    Kind Regards,
    Srikanth Pai
     
    Pai, Aug 29, 2003
    #1
    1. Advertising

  2. Pai

    Pai Guest

    "Teemu Keiski" <> wrote in message news:<>...
    > Just checking that do you have the <form runat="server" ...> set with
    > enctype="multipart/form-data" attribute as it is needed for uploading to
    > work?
    > --
    > Teemu Keiski
    > MCP, Designer/Developer
    > Mansoft tietotekniikka Oy
    > http://www.mansoft.fi
    >
    > AspInsiders Member, www.aspinsiders.com
    > ASP.NET Forums Moderator, www.asp.net
    > AspAlliance Columnist, www.aspalliance.com
    >


    Hello Keiski,

    I have included all these in the form tag.

    The problem here is that since the button is a asp.net server control
    it fires the postback event and the contents of the <input type="file"
    is lost and the value becomes "" when I click the button.

    I want the value to persist even after the post back....

    Any suggestions,

    Kind Rergards,
    Srikanth Pai
     
    Pai, Sep 2, 2003
    #2
    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. Roberto
    Replies:
    3
    Views:
    335
  2. Ron Brennan
    Replies:
    5
    Views:
    344
    Dr John Stockton
    May 14, 2004
  3. Randell D.
    Replies:
    12
    Views:
    274
    Randell D.
    Jul 6, 2005
  4. Tarkeshwar
    Replies:
    2
    Views:
    211
  5. Vincent van Beveren

    Switich Input field from TYPE=TEXT to TYPE=PASSWORD

    Vincent van Beveren, Jul 13, 2006, in forum: Javascript
    Replies:
    5
    Views:
    192
    Randy Webb
    Jul 13, 2006
Loading...

Share This Page