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 577299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:08:20+00:00 2026-05-13T14:08:20+00:00

ok i am downloading a file from a server and i plan to delete

  • 0

ok i am downloading a file from a server and i plan to delete the file that i have downloaded on the server after it gets downloaded on the client side..

My download code is working fine but i dont know when to put the command to delete the file.

string filepath = restoredFilename.ToString();

            // Create New instance of FileInfo class to get the properties of the file being downloaded
            FileInfo myfile = new FileInfo(filepath);

            // Checking if file exists
            if (myfile.Exists)
            {

                // Clear the content of the response
                Response.ClearContent();

                // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
                Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);

                //Response.AddHeader("Content-Disposition", "inline; filename=" + myfile.Name);
                // Add the file size into the response header
                Response.AddHeader("Content-Length", myfile.Length.ToString());

                // Set the ContentType
                Response.ContentType = ReturnExtension(myfile.Extension.ToLower());

                //// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
                Response.TransmitFile(myfile.FullName);

                // End the response
                Response.End();

            }

Now i know the response.End() will stop every thing and return the value, so is there another way too do so..

I need to call a function

DeleteRestoredFileForGUI(restoredFilename);

to delete the file but dont know where to put it.. i tried putting before and after Response.End() but it does not work..

any help is appreciated… thanks

  • 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-05-13T14:08:21+00:00Added an answer on May 13, 2026 at 2:08 pm

    Add

    Response.Flush();
    DeleteRestoredFileForGUI(restoredFilename);
    

    after the call to TransmitFile() and ditch the call to Response.End() (you don’t need it).

    If that does not work, then ditch TransmitFile() and go with:

    Stream s = myFile.OpenRead();
    int bytesRead = 0;
    byte[] buffer = new byte[32 * 1024] //32k buffer
    while((bytesRead = s.Read(buffer, 0, buffer.Length)) > 0 &&
          Response.IsClientConnected)
    {
       Response.OutputStream.Write(buffer, 0, bytesRead);
       Response.Flush();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After downloading files from a remote UNIX FTP server, you want to verify that
I have an ASP.NET program where i am downloading a file from web using
Is there a difference between directly downloading a file from a web server, and
I'm working on a Silverlight control that will allow multi-file downloading. At the moment
I'm downloading an entire directory from a web server. It works OK, but I
I'm downloading some images from a service that doesn't always include a content-type and
I have a requirement to download a PDF file and saving it on clicking
System.out.println(s.toString().substring(0,s.indexOf(.mp3))); i am downloading file from android application.. i need to name them as
1) when i am downloading the file from net my frameworks are getting in
I am creating an application where i am downloading a large file from dropbox

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.