Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:59:16+00:00 2026-06-10T01:59:16+00:00

I wonder if anyone knows this one. I was getting a pretty tough error

  • 0

I wonder if anyone knows this one.

I was getting a pretty tough error on my asp.net vb web app. I tell you I nearly had qwerty emblazened on my forehead for bangin my head against the keyboard. But I think I figured out the cause of the error:

I have the following code:

 fileToDownload = createFileSet(fileToDownload, confirm)
                    HttpContext.Current.Response.ClearContent()
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileToDownload.Name)
                    HttpContext.Current.Response.AddHeader("Content-Length", fileToDownload.Length.ToString())
                    HttpContext.Current.Response.ContentType = ReturnExtension(fileToDownload.Extension.ToLower())
                    HttpContext.Current.Response.TransmitFile(fileToDownload.FullName)
                    HttpContext.Current.ApplicationInstance.CompleteRequest()
                    Directory.Delete("C:\temp_" & confirm, True)
                    'System.IO.File.Delete(fileToDownload.FullName) <--- Error here

When I take the comment tick off that last line I get a real ugly error (I could redo it and spell it out, what kind of error, but it really doesn’t matter).

I think I know the cause. The user is downloading a file, or in process of, or something, and the program is attempting to delete it… causing the error.

Is there a way of creating some on HttpContext.Current.Response.TransmitFile.complete (code made up) or am I resorted to a batch file and a windows scheduler to clean up these files that are no longer needed?

Is my error conclusion correct, you think? I really don’t see a way of creating an “on event” but I’m too new at asp.net to know for sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:59:18+00:00Added an answer on June 10, 2026 at 1:59 am

    Try using a finally block (got the idea from here http://forums.asp.net/t/1436818.aspx/1 ). Inshort do this…

    try {
     fileToDownload = createFileSet(fileToDownload, confirm)
                        HttpContext.Current.Response.ClearContent()
                        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileToDownload.Name)
                        HttpContext.Current.Response.AddHeader("Content-Length", fileToDownload.Length.ToString())
                        HttpContext.Current.Response.ContentType = ReturnExtension(fileToDownload.Extension.ToLower())
                        HttpContext.Current.Response.TransmitFile(fileToDownload.FullName)
                        HttpContext.Current.ApplicationInstance.CompleteRequest()
                        Directory.Delete("C:\temp_" & confirm, True)
    } finally {
        System.IO.File.Delete(fileToDownload.FullName)
    }
    

    Or do this:

    You could read the zip file contents into a memory stream, delete the file then push the memory stream out to the response buffer. Only issue I can see with that is if the download fails and they want to try and get it again. Anyway heres a post showing you how to deal with files and memory streams and pushing it out to the response buffer http://www.c-sharpcorner.com/UploadFile/jhblankenship/DownloadingFromMemStream11262005060834AM/DownloadingFromMemStream.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone can help - I have this error showing recently when
I wonder if anyone can explain the syntax in one line of this snippet
I wonder if anyone knows a jQuery plugin that meets the following characteristics: It
I wonder if anyone else has seen this before: I have the following ZCML:
I wonder where this error is coming from. Here is the code, and below
Before I wander off and roll my own I was wondering if anyone knows
I wonder if anyone can point me in the right direction I'm fairly new
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I wonder if anyone has an idea how you have to transform an image
I wonder if anyone else is facing the same issue. I have a UITextView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.