简体   繁体   中英

Asp.net troubles with file uploads

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM