FileUpload problems

  • Thread starter Thread starter Knoxy
  • Start date Start date
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
 
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.
 
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
 
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.
 
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...
 
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 :-)
 
Back
Top