0

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.

4
  • 1
    Try add name tag to input like <input id="transcript" name="transcript" type="file" /> and check the Request.Files collection in Watch window on debug mode if it contains any file. Also keep in mind that IIS has default limitation on the file size, you can change it in web.config Commented Dec 4, 2012 at 14:15
  • @lavrik that worked but now I am receiving a "The given path's format is not supported." error? Commented Dec 4, 2012 at 14:32
  • Nevermind, figured that out as well, needed to use the Path.GetFileName. Commented Dec 4, 2012 at 17:46
  • @Spacemancraig glad to help :) When posting any form the input/select name tag will actually the thing you see on the server side. Commented Dec 5, 2012 at 12:25

1 Answer 1

2

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

2 Comments

Unfortunately this won't work because the actual form page is just standard .asp and not an .aspx
Ah fair enough. There's usually a good reason, I'm glad you got it sorted anyway =]

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.