views:

16

answers:

2

i am using file upload control in server side when iam trying to get the file it is showing no file present

<asp:FileUpload ID="upldDocument" runat="server" />
string fileExtension = System.IO.Path.GetExtension(upldDocument.FileName);
if (upldDocument.HasFile)
{
}

i am getting a empty string as file extension and upldDocument.HasFile is returning false even after selecting a file. what could be the reason??

A: 

How are you checking the values? (in what event)

Did you set the enctype attribute of the form to "multipart/form-data" ?

CyberDude
+1  A: 

Based on the posted code, I can only offer a best guess. There's not enough code posted to be sure what the problem is, but here's my best guess:

If you're not already, you need to check the HasFile property.

See here for a full example:

Edit - added

Using HasFile AFTER the bad code won't help. You need to put the code to get the extention inside an if statement so that it only attempts to read the extension if there IS a file.

string fileExtension = "";
if (upldDocument.HasFile)
{
  fileExtension  = System.IO.Path.GetExtension(upldDocument.FileName);

}
else
{
   //No file selected by user, which is why you can't get the extension.
   // handle this eventuality here even if it means just returning from the function and not doing anything.
}
David Stratton