Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > <input type="file"

Thread Tools

<input type="file"

Posts: n/a
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.F ileName);
string srcFileName =
System.IO.Path.GetFileName(fileBrowse.PostedFile.F ileName);

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

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
Reply With Quote
Posts: n/a
"Teemu Keiski" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
> AspInsiders Member,
> ASP.NET Forums Moderator,
> AspAlliance Columnist,

Hello Keiski,

I have included all these in the form tag.

The problem here is that since the button is a 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
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off