FileUpload problems

K

Knoxy

Hey all,
I hope someone can help me on this one as it's driving me nuts.

Basically i have the asp:fileupload control embedded on my page but,
hasfile 'always' returns false. I have tried using the
enctype="multipart/form-data" on my form but that doesn't make any
difference.

I have this working on an asp.net 1.1 (using <input type=file>) and
it's fine but this sites asp.net 2.0.

My code is as follows:
<form enctype="multipart/form-data" runat="server" method="post"
id="frmFileUpload">
<asp:FileUpload ID="fuFilename" runat="server" Width="400" />
</form>

Is there anything I'm missing? Any ideas much appreciated!
Andrew
 
J

Jacob

I think the interesting thing is more your code behind. There seems to
be nothing wrong with your HTML markup except that it's not necessary
to specify the enctype.
 
K

Knoxy

Cheers for getting back to me Jacob, appreciated. There isn't really a
lot going on in code-behind but what I have is:

#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
...
// code doesnt get called when upload button is pressed
}
}
#endregion

#region UploadFile_Click
public void UploadFile_Click(object sender, EventArgs e)
{
if (fuFilename.HasFile)
{
// code doesnt get called as its saying HasFile is false
}
else
{
lblNoFile.Visible = true;
}
}
#endregion

Any ideas?
Cheers,
Andrew
 
J

Jacob

There's a thread here -
http://www.developersdex.com/asp/message.asp?p=2910&r=4884890

Sounds like the problem is that the file stream is not being sent or
that it is being erased before being used. You could try to check
whether other event handlers overwrite the value before the click
handler gets fired.

Another option is to check that the filecontent.length is greater than
0. This is what I normally do.
 
K

Knoxy

I tried checking the filecontent.length but that was zero. I will try
checking out any other events that could be firing and removing the
file...
 
K

Knoxy

Solved.

There was another form wrapped up around the <body/> contents that
seemed to affect the file upload.

Thank you for your help Jacob and I hope this helps anyone else with
this problem! I knew it had to be something stupid :)
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top