Reputation: 1396
Our company has a form setup on our website for scholarship applications and I am having an issue with getting file uploads to work. I am using an asp.net page in C# to handle the form data.
From the form:
<form id="scholarForm" name="scholarForm" enctype="multipart/form-data" method="post" runat="server" action="upload_form.aspx">
<input id="transcript" type="file" />
The asp.net page handling the data (code edited for relevance):
protected HttpPostedFile transcript;
transcript = Request.Files["transcript"];
transcript.SaveAs(@"c:\Dollars Applicants\" + fullName + "_" + memberNumber + @"\" + transcript.FileName);
This just produces a null reference error and I am not sure why. I have tried uploading several different file types with no success.
Upvotes: 0
Views: 107
Reputation: 6372
Try using a FileUpload
control. (Docs: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx)
Form code:
<asp:FileUpload runat="server" ID="fuTranscript" />
Code behind:
if (fuTranscript.HasFile)
{
fuTranscript.SaveAs(@"c:\Dollars Applicants\" + fullName + "_" + memberNumber + @"\" + fuTranscript.FileName);
}
Upvotes: 2