1

i need to get the filename from my input id is Announcement_PIC, but it always return null when i try to get the filename. below is my code:

Front side:

<input type="file" runat="server" class="textboxTabsFiles" ID="Announcement_PIC"/>

Backend: i've already included the below in the partical class:

protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;

This is how i'm currently getting my filename

string fn = System.IO.Path.GetFileName(Announcement_PIC.PostedFile.FileName).ToString();

Edit: my file upload is placed inside a JQuery tabs and using the asp fileupload it also has problem getting the file name, thus i tried using input file

3
  • on which event do you have this code ? why aren't you using Asp's FileUploader Commented Aug 3, 2012 at 13:06
  • In the RSS feed, this question's title creates a file up-loader box like the one here: File Upload. Pretty nifty. Commented Aug 3, 2012 at 13:12
  • Are you performing an async postback or a full postback? Commented Aug 4, 2012 at 7:31

3 Answers 3

1

Have you remembered a enctype='multipart/form-data' on the form-tag?

Sign up to request clarification or add additional context in comments.

Comments

1

Why not use:

<asp:FileUpload id="FileUploadControl" runat="server" />

That will allow you to access .HasFile & also perform .SaveAs

Comments

1

If you are using webforms take a look on FileUpload.

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.