<input type="file"

P

Pai

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
 
P

Pai

Teemu Keiski said:
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
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top