Here I am providing the code snippet that will allow us to delete the file once the file is downloaded on the client’s machine. Below are the code snippets
C#
private void DownloadFile()
{
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition","attachment; filename=myFile.txt");
Response.WriteFile(Server.MapPath("~/uploads/myFile.txt"));
Response.Flush();
System.IO.File.Delete(Server.MapPath("~/uploads/myFile.txt"));
Response.End();
}
VB.Net
Private Sub DownloadFile()
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", "attachment; filename=myFile.txt")
Response.WriteFile(Server.MapPath("~/uploads/myFile.txt"))
Response.Flush()
System.IO.File.Delete(Server.MapPath("~/uploads/myFile.txt"))
Response.End()
End Sub
Comments
Post a Comment