Hey people...

I want to delete the file from the server when he is been successfully doownloaded from the server (one-time download)... how can i this ?
For send file I`m using the method transmitFile(...)...

Thanks.

Hey people...

I want to delete the file from the server when he is been successfully doownloaded from the server (one-time download)... how can i this ?
For send file I`m using the method transmitFile(...)...

Thanks.

To delete a file - use System.Io.File.Delete("absolute_filepath") method.

To delete a file - use System.Io.File.Delete("absolute_filepath") method.

But i want it to be an implement event, when the file has been downloaded then the same file to be deleted from the server :/

But i want it to be an implement event, when the file has been downloaded then the same file to be deleted from the server :/

Maybe this will help:

String filename="info.txt";
        String path=MapPath("~/aa/info.txt");
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename );
        Response.AddHeader("Content-Type", "Application/octate-stream");
        Response.AddHeader("Content-Length", new System.IO.FileInfo(path).Length.ToString());

        Response.TransmitFile(path);
        Response.Flush();
               
        System.IO.File.Delete(path);
        Response.End();

The most likely, when you transmit the file and then trying to delete the transmitted file, you may receive the IO exception. Because system may try to delete a file that it currently in use.

It is better to setup a scheduled task that will delete such files at specific intervals.

  System.IO.File.Delete(Server.MapPath("~") + ConfigurationManager.AppSettings["PictureDeleteDirectory"]+filename);

  Web.Config:

  <configuration>
  <appSettings>
    <add key="PictureDeleteDirectory" value="\\Images\\"></add>
  </appSettings>
  <connectionStrings></connectionStrings>
This article has been dead for over six months. Start a new discussion instead.