Wednesday, March 22, 2006

File Upload Frustrations

In .NET 1.1 it is relatively simple to provide file upload functionality using an HtmlInputFile control e.g.

<input id="inputFile" type="file" runat="server">

Where I ran into problems was when the file exceeded the maximum size. This is controlled by the maxRequestLength attribuite of the httpRuntime element in the config file hierarchy. The default value is 4096 KB. After some expoerimentation I determined that the error could only be trapped by the Application_Error event handler in global.asax.cs. I wanted to redirect back to the calling page and display a message but I could not get this to work. Some research showed that I was not alone:

I ended up using Response.Write() to output an error message on the empty page that resulted from Server.ClearError() in the event handler (you need this to stop the error bubbling up to be handled as defined by the customErrors element in web.config). I added an <a> tag that contained a JavaScript link to take the user back to where they came from but was not particularly happy with this solution.


Post a Comment

<< Home