Steffano Soh
Steffano Soh

Reputation: 121

Getting File from <input type ="file"> in C#.net

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

Upvotes: 1

Views: 9032

Answers (3)

user854301
user854301

Reputation: 5493

If you are using webforms take a look on FileUpload.

Upvotes: 1

Ryan McDonough
Ryan McDonough

Reputation: 10012

Why not use:

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

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

Upvotes: 1

Steen T&#248;ttrup
Steen T&#248;ttrup

Reputation: 3835

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

Upvotes: 1

Related Questions