Print This Post

Minor updates to the ASP.Net file upload module

I’ve had a few requests for updates to the file upload module. These were mainly to fix some javascript issues. In all, the updates have brought the module up to version 2.0.3, which I have now made available for download.

The changes are:

  • BUG FIX: when uploads are cancelled or prevented on client side due to being too large the page is refreshed via script as this seems to be the only way to cancel the upload. Previously this was done using location.reload. However, this method resulted in a warning message on the browser and possible re-submission of the form content. I have changed the script to use document.location = document.location to refresh the page- this does not repost the contents or produce a warning.
  • BUG FIX: I have now updated the script so that the presence of at least one file to upload is verified before the progress bar is displayed. This prevents the bar being displayed when their are no uploads and allows other postbacks on the form.

Hope this helps and thanks again to those who continue to use the module and provide feedback.

Popularity: 14% [?]

There Are 56 Responses So Far. »

  1. I don’t know if I am overlooking something or not. When I try to remove the SQL functions from Upload 2, they seems to stick. Everything I try to do, it still trys to use the SQL connections to perform the upload. Am I missing something? I can use any number 1 & 3-8 and everything is fine. When I use “DJFileUpload2″, it goes to SQL connection. I tried changing the Processor type from SQL to FileProcessor it still tried SQL. Any suggestions or am I missing something. When I try removing 2 and 3 and just using the 1st Upload(while removing the SQL processor for 2 in the code behind), then I get an Object error. Maybe something hard coded?

    Thanks for the work on this excellent tool. Saved me some major bucks on my little project.

    Rob

  2. Arggg… The References were on your build of FileUploadV2. I hate when I overlook something so simple.

    Thanks for sharing this with everyone… Very Nice!

  3. darren,
    it is nice control for upload.
    iam usins this control from version 1 on wards.
    recently i upgrade to version 2.0.3.
    in our system, i don’ have dotnet 2008, so iam rebuilding the solution in dotnet 2005 . iam getting following error
    ‘darrenjohnstone.net.FileUpload.UploadWorkerRequest.SendCalculatedContentLength(long)’: no suitable method found to override in UploadWorkerRequest.cs file.

    can i comment this method as same method is not there in dotnet 2005?

    thanks in advance.

    from
    ram

  4. Hi Ram,

    There’s no reason why this should be happening. Although the solution is built in VS 2008 it is targetted and designed for .Net 2.0. Also, SendCalculatedContentLength has been around in the HTTPWorkerRequest class since at least v1.1 of the framework- so something else must be wrong (http://msdn.microsoft.com/en-us/library/kfwh96kx(VS.71).aspx).

    You should check your references etc. and ensure that you are building correctly.

    Cheers,
    Darren

  5. Hello! Thanks so much for this great tool!

    I am having a problem and cannot find a help area on your site. I apologize if I am overlooking something. Perhaps you can e-mail me if this is not the right forum for technical issues.

    I have a shared site on GoDaddy.com. I cannot install the library on the server so I have to reference it from the bin folder in the download you have provided. However, I am getting a security exception when the web.config tries to read it. I think this is the file is in full trust, like you said, but GoDaddy.com runs has a medium trust environment.

    Is there any work around for this, or will I not be able to use your upload module? If I can’t, can you recommend something I could use? I have searched the web for weeks looking for help in this area, and have not found much. Your solution is by far the best one out there, so I am hoping you can provide me some help in this area.

    I mainly needed a progress bar because the users will be uploading up to 200mb files and it’s just to long of a wait without giving the user some type of information. However, the entire package here is really nice, and if I can get this working I will be switching completely to your module.

    Either way, thanks so much for providing such a nice solution.

  6. Hi Chuck,

    Unfortunately the module will only work with medium trust if the DLL is installed in the GAC. This is a security precaution imposed by the framework and there is no workaround.

    I can’t think of another upload module which doesn’t have a similar restriction. Most rely on doing something which requires trust. If I come across anything though I will let you know.

    Cheers,
    Darren

  7. Hi Darren, a while back a couple of people including myself were asking about getting your control to work in DNN. I’m wondering if you (or someone else) has figured out how to get the control working in DNN?

    Thanks-

  8. Hi Darren,
    First of all, thank you very much for your great component, The flexibility is amazing.
    I haven’t finished to configure it at all but (if I’m not wrong) there’s atm no Property to hide the “Remove” Button (you can hide the add button and co.) I’ve added the property myself but I think it could be good if you integrate it in your next version.

    Regards,

    Pit.

  9. Hi,

    Thanks for writing this excellent tool! I’ve successfully included this into my code but I’m having a problem which I was hoping someone could help me with.

    I have a form with other fields as well as this upload facility and I need to try and ensure that if the form didn’t pass the validation tests then the file isn’t uploaded. I have tried altering the IFProcessor code (startNewFile method) to include some tests on the form but can’t get it to work (i’m new to .net). Has anyone got any ideas on how I can only upload files if the server has validated the form (bad users will try playing with the form with script disabled).

    Secondly, does anyone know if its possible to prevent someone with script disabled to upload a file with an invalid file extension (.exe)?

    Many thanks for your help.

  10. Hi Rob,
    I’ve got some DNN code ready to make into a module. The control itself does work although some things need to be taken into account for DNN. I’ll be publishing the module soon and will send you a mail when I do.

    Cheers,
    Darren

  11. Hi Pitoo,
    Thanks for this. I’ll add the remove button property into the next version.

    Cheers,
    Darren

  12. Hi Javier,
    You’ve got the right idea with the StartNewFile method. All you really need to do is throw an exception if the file extension is invalid. The next version of the module will have server side file extension checking built in by the way- this should be out in the next few weeks.

    Cheers,
    Darren

  13. Hello Darren,

    Thanks for writing this great code. We’ve incorporated te code in our CMS. I found a design issue with the following code:

    public class UploadModule : IHttpModule
    {
    public UploadStatus Status
    {
    get { return _status; }
    }

    There will be one module object instance that is shared by
    all requests. Putting the _status instance field on this single
    module instance is not a good idea. Problems will come with
    almost simultaneous uploads.

    I have refactored the code and made the status field a property of the formstream. As there is one formstream instance for each upload request, this is a better place.

    I have added the following code:

    // Prevent browser caching
    response.Cache.SetCacheability( HttpCacheability.NoCache );

    // Flush
    response.Flush();

    // End
    response.End();

    to the ProcessRequest method in the UploadProgressHandler class.
    This prevents browser caching of the progress.

    I have added Crc32 computation to the upload:

    public void Write( byte[] buffer, int offset, int count )
    {
    if ( _errorState ) return;

    try
    {
    _fs.Write( buffer, offset, count );
    _crc32.Update( buffer, offset, count );
    }
    catch ( Exception )
    {
    _errorState = true;
    throw;
    }
    }

    I use the crc32 class from ICSharpCode.SharpZipLib.Checksums.Crc32.
    I store the crc32 in a database, an later on i use this crc to
    check if the uploaded file already exists on the server.

    Furthermore i’ve expanded the number of properties on the UploadedFile:

    public UploadedFile( FileSystemProcessor processor )
    {
    // Get upload properties
    ClientName = processor.GetFileName();
    ClientPath = processor.GetClientFilePath();
    ContentDisposition = processor.GetContentDisposition();
    ContentType = processor.GetContentType();
    FieldName = processor.GetFieldName();
    Name = processor.GetFileName();
    PhysicalPath = processor.GetPhysicalFilePath();
    PhysicalTempPath = PhysicalPath;
    Path = PhysicalPath.Substring( LynkxSystem.PhysicalApplicationPath.Length + 1 ).Replace( ‘\\’, ‘/’ );
    Crc32 = processor.GetCrc32();

    // Get file info
    var fileInfo = new FileInfo( PhysicalPath );
    if ( fileInfo.Exists )
    ContentLength = fileInfo.Length.ToString();
    }

    Lastly i have added a cleanup event:

    static void Context_EndRequest( object sender, EventArgs e )
    {
    // Check for upload status
    var app = sender as HttpApplication;

    // Remove status if present
    var status = UploadManager.RemoveStatus( app.Context );

    // Delete unsaved uploads
    if ( status != null )
    status.DeleteUnsavedUploads();
    }

    I hope that this feedback helps improve the code. I’ve heavily
    refactored your code. If you want it, please send me an email.

    Regards,
    Gjalt Wijma

  14. Darren
    Thank you for sharing such great tool. It just works great.

    I added the file upload control to my form and it works great. But there are couple of instances where the upload starts when it should not have. In my form if CANCEL is clicked and a file was selected, the file gets uploaded. Also, the file upload starts on any server postback events, such as button events on the form.

    Is there a way to let the upload start only when the form is ready, such as only on submit button clicked?

    Thanks for the great work.

  15. Darren,

    I’m having a couple issues.

    First I get a JavaScript error using MSIE7 in the fileupload.js file up_BeginUpload method on the first if statement of “if (!Page_IsValid) return;”. Debugging says “Page_IsValid” is not defined. So I added a local JavaScript script to assign “var Page_IsValid=true;” and that got around that for the time being.

    Second, I’m using the DJ FileUpload control and when I click “upload”, I see the AJAX progress bar, but it never uploads a file. I checked the UploadProgress.ashx and the contents is always “empty”. None of the files get loaded and the progress remains at 0. If I disable the use of the scripts (just rename upload_scripts dir), then the files get uploaded, but the progress bar doesn’t work. So I know the file upload process works, but there’s something else in the scripts that’s not working and not throwing any exceptions/errors that I can find.

    thanks

  16. Oh, I’m using FireBug on Firefox to see the URL parameters and http response on the UploadProgress.ashx calls.

  17. Nice pieces of code. I need to store to SQL additional file related attributes like a user file description. The file name and content type came from the httprequest. Then how can I add additional element to the control and get those attribute within the list?

  18. I think I figured out my problems. I had the controls inside of an UpdatePanel, since I had my own AJAX based ‘wizard’ using views and multiview controls. The file upload was one view that was a couple steps into the ‘wizard’. I removed all of the steps to individual pages and the upload works fine now.

  19. Hi Jim,
    You’ll can use hidden fields for this and then access them from the PreviousFields collection. See here http://darrenjohnstone.net/aspnet-file-uploaddownload-module-v2-documentation/. Cheers

  20. Good Component. Thx.

    I am new using your module and I already have a doubt. :)

    How might I add metadata to the uploaded file, for example, I wan’t to add a description for the file and store it in the database by myself.

    Best regards,
    Marco Alves.

  21. Good Module. Thx.

    I am new using your module and I already have a doubt.

    How might I add metadata to the uploaded file, for example, I wan’t to add a description for each file being uploaded (I want to upload many files at a time) for the file and store it in the database by myself.

    Best regards,
    Marco Alves.

  22. I changed the control so that I can add any type of control for each file being uploaded. Validation is also possible. Not just to the whole form, but as i said, for each file.

    If anyone wants it, mail me marco2250@gmail.com

  23. Hi Darren

    I have a problem of implementing the upload module with the Master-Content page. If I have the Upload Controller and Progress Bar inside a content place holder as followed:

    Then I get the error message at up_killProgress function says that “;” is expected. Error is at the line:
    up_killProgress(‘ctl00_MainContentPlaceHolder_DJAccessibleProgrssBar2′)Sys.Application.initialize();

  24. I figured out the problem. If you have a form tag with runat=server in the Master page and insert the Upload Controller and ProgressBar in the Content page then the upload module will display error. It doesn’t when you put the form tag with runat=server in the Content page.

    However, this is not a solution since you may have some controls in the Master page that require the form tag such as ScriptManager in Ajax.

    I look forward for a fix.

    Cheers

  25. My MSIE6 users report getting an hourglass and the browser locking up after clicking on Upload button. MSIE7 and Firefox users can upload documents without any problems. Is there anything specific that doesn’t work with MSIE6 and is there a way to fix it?

    thanks,

  26. Darren,

    How can I limit the module to only run for a specific folder. I tried the following in my web.config but when I set a location for the module it never loads.

  27. Hello, thank you for the library.
    I have a very obvious feature request: MinFileUploads and ShowRemoveButton for the upload control.
    I currently achieve an unremovable box by hiding the button in styles, but it’s an backasswards way.

  28. Hi Darren,

    Fantastic component as said before. A quick question though, Can I make the file input text boxes bigger and change the position of the Browse and Remove buttons?

    I have changed the CSS styles but does not seem to have an effect. Do I have to modify the fileupload.js script at all? Any pointers would be appreciated.

    Cheers,

    Mike

  29. I really like this module.I searched long time for usefull, customizable file upload progress module. Your module was tested with few other commercial solutions. After real life testing with multiple users uploading multiple large files, and other users doing some other task, i must say that your module won. It is rock stable even on very slow connections, and is working great with mine Custom URL Rewriter and some other modules. Of course I customized some parts of it to met my needs.

    Also i think there is bug in module, related to uploading of files with non-english characters in filename or path. For Example if user try to upload one of those files, using file upload with ID “File1″, and submits it. Your module would upload file on server without problems. But when i try to collect filename of uploaded file I get
    File1.PostedFile.FileName = null , eg File1.PostedFile = null, File1.Value=”"….( System.NullReferenceException: Object reference not set to an instance of an object ). When File1.Value conatins contains non-english characters module would Dispose PostedFile.

    Can you or someone help me to find where this happens and fix it?

    Also it would be great if your Module could work normally with ASP.NET AJAX Extensions.

  30. I’m attempting to use this control on a site built on Dynamic Data. I’ve got a separate page for handling our bulk uploads using the upload module and it works great. The problem I’m running into is using a file upload on one of the Dynamic Data editing pages.

    What I really need to be able to do is turn off the upload module so that I can process a regular asp:FileUpload control when I’m in the Dynamic Data pages. Is it possible to turn off the module so that it doesn’t intercept the incoming requests or to setup the module to pass everything through as if it wasn’t there.

    When I have an asp:FileUpload control on the page, it never picks up a file (which I believe is expected). If the DJFileUpload control is used, the page won’t respond to a submit from the Update or Cancel buttons, only from the upload button in the control (which doesn’t make sense for a page editing 10 data elements with the upload being one of them).

    Are there any options to make this work or am I looking at one or the other?

  31. hello.
    i am trying to add upload module ver2 to a solution which already contains the normat upload of Visual Web Developer 2008 express.

    i downloaded and installed the Setup file but i don’t have the new library components in the toolbox when i open my solution.

    why is that?

    i thought of downloading upload moduke ver1, but i can’t find the required DLL files in the DOWNLOADS. where can i find it?

    thanks !

  32. Hi Darren,

    Could you point me to information on how to implement the control in a DNN module?

  33. Hi,

    Do you have any unit tests for this?

    Thanks

    Kieran

  34. 円光探して楽しい生活始めてくださいね。

  35. いつも家出サイトでは少女達が出逢いを探しています。
    家出サイトでは少女達が神待ちしています。
    テレホンセックスしたい人向けのサイト

  36. 掲示板でメル友募集してます。
    メル友を安心して見つけてください。高校生メル友探しのオススメサイト
    高校生との出会いを探しているなら高校生メル友サイトからどうぞ。
    人妻と余裕でセフレになれる。

  37. 出会う方法お探し案内所
    出会いがあるから紹介したい!優良サイトで探してください。素敵な出会いを提供出来ます。
    出会い系サイト比較の決定版!!出会い系サイト使い放題無料出会い系サイトで出会い探し始めませんか?

  38. 少女達は家出をしたいから急いで男性会員を探しています。家出サイトで多数募集している男性会員います。女の子も家出をするなら楽しくしたいですよね?安心してください。セフレを沢山作ってセフレパーティーしよう。

  39. 出会い系サイト恋のラブステーション年齢認証不要のラブステーションは出会いたい時に出会える男女がかなり登録しています。
    出会いが欲しいなら出会い系サイトで無料で登録して掲示板等を使って相手を探してください。
    恋人探し専門の出会い系を使って、楽しい出会いを見つけてください。

  40. 出会う事の出来る出会い系サイトへ登録しましょう。楽しい出会いが必ずあります。出会うためには色々な方法で募集しましょう。出会う事の出来る優良サイトで探して人妻と出会う事も出来る。

  41. Hi Pitoo,
    You can hidden “remove button” with css setting:

    upRemoveButton
    {
    visibility:hidden;

    }

  42. hi congratulation for your uploader!!! i got a litle problem,

    i’would like to to check the submit of download starting…

    if i select a file of uploader and press on a button of the page i’d wish download can not start,how can i do?

  43. Hi Darren,

    I have a problem when a form has multiple buttons. When I click on a random button and there is a file selected the file will be uploaded. What I want is to assign a button which will trigger the uploadevent. Is this possible?

    I’m using the standard .net fileupload control for selecting a file.

    Regards
    Max

  44. Hi Darren,

    Thanks for the great tool. I am using an ASP.Net application with VS 2005. I think I’ve installed everything according to your instructions, but I do not see the progress bar when my files upload. Any idea what I could be missing?

  45. Is there a way to check if the user uploaded a real file? In IE 6/7 you can upload a file that does not exist (by typing in a fake file name and uploading it) and empty file will be created at the server.

  46. Hi Darren,

    Have been using FileUpload for a while and it’s great. There is one thing that I just can’t work out. I create an instance of the controller and upload control from a sub page of my app, eg. /userupload/uploadpage.aspx. To get the whole thing to work properly I then have to put the three style/script directorys both at the top level/ and the /userupload/ level of my app. I just cannot figure out a way to get the thing working with just one copy of these files. It seems I can configure the controller options, but it still needs files at the root level. Hope I make some sense. Any ideas ?

    Thanks,

    Matt

  47. Hi Darren –

    Thanks for all your great work.

    I’m having a problem that I’m wondering if you can help me with. I’m trying to use your control in my ASP.NET 3.5 app. Everything works great when I’m just testing it on localhost using the Visual Studio Development Server. But when I deploy to my production server running IIS7, the file upload progress bar gets displayed and everything *seems* to work, but the files don’t actually get saved to disk (I’m using FileSystemProcessor). I don’t get any errors, but the files don’t end up where they’re supposed to on the server. Any ideas how I can diagnose this?

    Thanks in advance.

  48. While accessing the survey webpart i am getting a error like $Resources:msg_error.

    Please let me know if any one solved this error.

  49. Settings:
    - maxRequestLength=”2097151″
    - maxAllowedContentLength=”2147483648″

    The problem is when trying to upload files larger that 2 Gb.

  50. Darren,

    Thanks for the great control.

    I was wondering if there was a way to use a basic asp.net file upload control without having to use the DJUploadController if I am using your control elsewhere on my site? From what I’ve seen I looks that like I have to us the DJUploadController even if I just want basic upload capabilities.

  51. Hi Darren,

    Nice tool, will it work for IIS5. i checked your documentation and says it works for IIS6 and 7.

    Thanks
    Nag

  52. I used this in VS2008 and is working fine..but after publishing in IIS5 its behaving strangely like the page is not hitting the javascript part…
    Thanks
    Nag

  53. Hi Darren,

    I am integrating your work I was so very lucky to stumble upon into my custom web control so have much to read/rewrite…

    I just wrote to Gjalt (comment #4045) to get his code changes since I will also have an issue with simultaneous uploads.

    I my be wrong but it seems that if two users upload a file with the same name, there would be a problem. In FileSystemProcessor, the file name isn’t generated but comes from http header parsing… I would go and randomize the on disk file name (I will add a _onDiskFilename attribute on UploadedFile class).

  54. Hi,

    what a very cool component. But I’ve a Problem with the Module because I need to differentiate between an uploadcontrol that has to use the Module and a “default” uploadcontrol that don’t have to use theses module.

    is there a easy way to do this?

    thx
    Daniel

  55. Hi Joy,

    I had the same problem. It is caused by a conflict between the Prototype library used by Darren’s code and JQuery.

    Check out the following links for more info:
    http://dev.jquery.com/wiki/PrototypeAndJQuery
    http://docs.jquery.com/Using_jQuery_with_Other_Libraries

    If you have tons of code using JQuery, it may be easier to rewrite Darren’s code to use Jquery

  56. Hi Darren,

    We are trying to maximize the number of parallel uploads our site can handle. The file size can be big (1G) and we stream it directly to the disk.
    As far as we could see, the current version of your upload module holds on a worker thread during the whole upload.
    The key part seems to be the loop in Context_AuthenticateRequest method, in FileUploadLibrary\UploadModule.cs.

    Is there any way to implement this asynchronously? Instead of calling worker.ReadEntityBody(data, bufferSize) in a loop, we’d call it only when we know that there’s enough data there to be read. For example if the upload is low, like 10k/sec, this code would only run once in every ~6 seconds (assuming a 64k buffer) and could give the thread back to the thread pool while waiting for the next chunk of data.

    Petter