ASP.Net File Upload/Download Module Version 2 (beta 3)
I know it’s not been very long since the previous beta of the file upload module, but since I’ve now finished browser testing and fixed a few issues I thought it would be best to make a new release. So, beta 3 is now available in the downloads section. This version also includes the ability to configure the upload controller properties via the web.config file. This is the last new feature that will be put into version 2 of the module.
I’ve tested the module on the following browsers:
- Internet Explorer 6/7
- Safari 3.1.2 on OSX
- Firefox 3.0.1 on OSX
- Firefox 3.0.1 on Windows
The following issues were fixed:
- The progress bar now operates correctly on Safari (see below).
- The file extension warning message is no longer displayed twice.
- The graphical button for selection is now displayed correctly in IE6.
- Clearing of selected files now operates correctly on IE6 and IE7.
- The cancel download button is now preloaded and displayed correctly on Safari.
Configuration section
A new configuration section has been added to allow global configuration of the most common file upload settings. These can be overridden by setting the relevent properties in the DJUploadController class. The configuration section is optional.
To use the new configuration section you need to register it in web.config as follows:
<!-- Register the file upload configuration section --> <configSections> <section name="uploadSettings" type="darrenjohnstone.net.FileUpload.UploadConfigurationSection, fileuploadlibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af961ece0b692dfb"/> </configSections>
You can then set the properties un the uploadSettings section. See the sample application for an example.
<!-- File upload module settings --> <uploadSettings allowedFileExtensions=".pdf,.xls,.doc,.zip" scriptPath="/upload_scripts" imagePath="/upload_images" cssPath="/upload_styles" showProgressBar="true" showCancelButton="true" enableManualProcessing="true" />
The progress bar is now synchronous
The XMLHttpRequest for calling the progress bar handler has now been made synchronous instead of the previous asynchronous method. In addition to this a Thread.Sleep call has been added to the main loop in the form parser. This make the progress bar smoother and also allows it to operate in Safari. For some reason, asynchronous calls would never be sent in Safari, although they worked correcty in Internet Explorer and Firefox.
The next release and what isn’t coming
I’m going to give it a couple of weeks for anyone to report any bugs and then release the final stable version of the module. Whilst I’ll be fixing any bugs that get reported after that I won’t be adding any new features to this version. This is mainly because I’ll be moving on to developing and releasing some other open source projects I have planned for ASP.Net and SharePoint.
In particular I won’t ever support ASP.Net 1.1 or Mono in this module. If you need support for either of these then I would suggest you take a look at Neat Upload.
Demonstration site
I’ve added a new demonstration site at http://demo.darrenjohnstone.net/fileupload. This will let you quickly try out the module to see if it is suitable for your needs.
Wrapping up
This turned out to be a fairly tricky project- and one which grew into a little more than I originally intended it to be. The original aim was to allow files to be uploaded in chunks and streamed to file processors which could then store the files in a database or other storage medium. I also wanted a progress par to be displayed to users and have slightly better looking user interface components.
I think I’ve achieved these things although I’m still not happy that I had to use reflection to set the proxy worker process. ASP.Net 2 includes much better memory management of file uploads and this combined with the streaming to file processors gives me what I was looking for.
The project is designed to be modular. You can take or leave the bits you need. The UI components can be used without the module and vice-versa. If anyone wants to change or extend anything then feel free. Also, I am sure there are many alternative- and no doubt better ways- to do some of these things and I would welcome any feedback which could help us all learn a little more.

Comment by ylee on 15 August 2008:
Hi Darren,
It’s me again. I got this to work within your solution that your provided with my modifications. When I include the project into my application the select button doesn’t work. It won’t launch the file browse event. All other buttons work except for the select button. I have tested it over and over again with different setups and it just won’t work in my application.
My is running another httpmodule to handle https redirect and I am running masters with viewstate protection. If you have any ideas about why it doesn’t work I would really appreciate it.
Comment by darren on 15 August 2008:
ylee,
The most likely cause is that the javascript file has not been included. Check the source of the page and get the include URL. Then try it in your browser and check it downloads correctly. If it doesn’t then set the property on the controller to specify the correct url to the folder containing the script. Let me know how you get on.
Cheers,
Darren
Comment by ylee on 15 August 2008:
Hi Darren,
I fixed the problem. I had to duplicate my project and remove and item at a time to see what was conflicting with the FileUploadModule. It turns out that it was a style class in my style sheet that was throwing the module off. The style was being used by another script called .hidden. Once I renamed that style class to something else, everything started to work. Thanks for your assistance. This module really help my alot. I would never have figured out how to write an http module.
Comment by ylee on 21 August 2008:
Hi Darren,
Since I got the module to work, I have been extensively testing it for problems. The biggest issue I am having right now is the max file size limit catch is not working. When it checks for maxrequestlength and goes into EndRequestOnRequestLengthExceeded the whole application just dies. It won’t return back to the calling page. I am trying to find answers but everthing seems to look good. Do you have any ideas on how to solve this problem?
Comment by Mark on 21 August 2008:
Howdy, Darren
I’m back again. I got a chance to update the DNN project I’m working on with B3. I’m still seeing DNN log me out whenever there is a successful file transfer.
Any ideas?
Also, I’ve built a WebService processor. In that processor I’ve created some additional propertites. I can access and set/get those properties, but I’m running into an events timing issue. I need to set the properties (e.g. from a separate drop down) before the user can successfully upload a file. Can this be done, or would the dropdown (from where the property value could be obtained by the processor prior to file upload) need to be added to your DJUpload control’s child control colletion?
Thanks,
Mark
Comment by darren on 21 August 2008:
Hi ylee,
I’ve caught the maximum file size issue in the next release, so don’t worry too much about that a fix is coming. Can I just check though- you’re not using IIS 7 are you?
Cheers,
Darren
Comment by ylee on 21 August 2008:
Hi Darren,
I am developing on IIS 7 but the application is running on IIS 6. I know its kinda wierd. I just haven’t had time to setup a Windows 2008 server w/IIS 7. Why do you ask?
Comment by darren on 21 August 2008:
Hi Mark,
Yes, that’s a bit of a problem. What happens is that the module runs before the form has been completely processed and hence when you set the values on your processor this will happen after the processor executes and so too late.
Adding the controls to the DJFileUpload control will not help with this. What you need to do is capture the values on a page and then move onto the upload form. You should pass the values of the drop down lists on the request to the upload page. In this way you can pass the values to your processor and attach the processor to either the DJUploadController (for defaults) or the individual upload controls.
Give me a shout if you need more detail on this.
Cheers,
Darren
Comment by darren on 21 August 2008:
Hi ylee,
The requests should be ended in different ways after an exception in IIS 6 and IIS 7. Just asking for my testing notes, the final module works in both.
Cheers,
Darren
Comment by ylee on 21 August 2008:
When should we expect the final release?
Comment by Mark on 21 August 2008:
Darren,
I understand about the timing issue and I realize that changing the DJUpload won’t work either.
So, are you saying I’d need a separate page for the dropdown (only 1 that would apply to all files selected in DJFileUpload control) to collect the value, and then I’d need to post it into a page that just contains the upload controller & the DJFileUpload?
Apologies ahead of time if I’m being dense.
Also any idea on why I’d get bounced out of DNN on a successful file transfer? I think watching the UploadModule.Context_AuthenticateRequest() method might be a start. Do you agree?
Thank you,
Mark
Comment by darren on 22 August 2008:
ylee - any time now. I’m just doing final testing.
Comment by darren on 22 August 2008:
Hi Mark,
Yes, basically you need to capture anything you’re going to use on a preliminary page and then pass the values to the upload page in the request.
Other options are to use javascript to get the values and pass them on the request of the upload page or alternatively to use hidden fields or cookies. Essentially you need to make sure that the values are available to the module before it starts passing anything to the processor.
Once final way (the most difficult but the best) is to change the form parser to interpret fields in the request form before the first file is processed. This already happens to a degree with the hidden fields for configuration. I’ll see if I can come up with a code sample or post about it.
Not sure about the DNN issue. I’ll install DNN later today and have a look at it.
Cheers,
Darren
Comment by Matt on 23 August 2008:
Hi Darren,
Great tool. However I get security errors when I run this in a shared hosting environment. Can you help ?
Matt
——————–
Hi Matt,
Your problem is related to trust levels in the .Net framework. Chances are that your web host has put your application into medium trust. The upload module will still work in this way but the assembly (FileUploadLibrary.dll) would need to be in the GAC.
Do you have control of your web.config?
Cheers,
Darren
——————–
Darren,
Yes I do have control of web.config. What do you reccommend ?
Matt
Comment by darren on 23 August 2008:
Hi Matt,
Your problem is related to trust levels in the .Net framework. Chances are that your web host has put your application into medium trust. The upload module will still work in this way but the assembly (FileUploadLibrary.dll) would need to be in the GAC.
Ask your web host what your options are. I doubt they’ll let you install in the GAC but they may allow your app to have full trust.
Cheers,
Darren