0

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??

2 Answers 2

1

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.
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.