how to auto remove file if user close browser?

5 posts, 0 answers
  1. AUK
    AUK avatar
    47 posts
    Member since:
    Oct 2004

    Posted 05 Aug 2013 Link to this post

    AsyncUpload is really come in handy, however I have a question which I don't know how to deal with:

    I have a page with AsyncUpload control and other normal text fields for user to update/insert a article with attachment, and I only want to save file after user click 'Save' button (so not only for saving file but other text fields as well), however the attachment is uploaded asynchronously, so a file is uploaded before user click 'Save' button, so my questions is how to remove the file if user decide not to save page or even close browser ?

    Many thanks!
  2. Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 07 Aug 2013 Link to this post


    The best way to handle this scenario is to use the default RadAsyncUpload configuration. It firsts upload files into the temporary folder and then on postback (clicking Save button) moves uploaded files from temporary to the target folder. Finally, all processed temporary files are deleted. Rest of the files that are not processed are cleared automatically after a set amount of time defined by the TemporaryFileExpiration property. Default value is 4 hours.

    Hristo Valyavicharski
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. AUK
    AUK avatar
    47 posts
    Member since:
    Oct 2004

    Posted 07 Aug 2013 Link to this post

    Hello, many thanks to your prompt answer, now I totally get it!
  4. Anu TM
    Anu TM avatar
    6 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post


    "Finally, all processed temporary files are deleted". Does that mean the files that are saved are immediately deleted and those files which remains unprocessed will remain for 4 hours?

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Aug 2013 Link to this post

    Hi Anu,

    The uploaded files are deleted immediately after the FileUploaded event has been fired. The rest of the files which are not uploaded or unprocessed will remain in the Temporary Folder for a period of 4 hours by default and the .NET framework will automatically delete them once the TemporaryFileExpiration duration is elapsed.

    There is only a rare chance for the CacheDependency to leave the files from getting deleted such as the server is rebooted unexpectedly (In this case Shutting down the application pool is enough to remove any leftover files) or you accessed the FileSystem and didn't dispose it.

Back to Top