ASP Snippets

Categories






Alerts

Free Alerts

Your email will always be
private and will not be shared.




Follow us on twitter.




Zoom In | Zoom Out


Author is awarded Most Valuable Professional award by Microsoft ASP/ASP.Net

ASP.Net - How to delete file from server after download is finished

Author:Mudassar Khan

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

 

That’s it. Try it and let me know in case any issues or queries.



Posted: Oct 08 2009, 04:42 by Mudassar Khan | Comments (1) RSS comment feed |
Filed under: ASP.Net | Tips

Views: 2860
Page copy protected against web site content infringement by Copyscape


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share





Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading




0  +  0  =   










Community News





Web Hosting SpotLight


Consulting


For consulting and work related queries click here.



Advertise


Advertise with us. For more details click here.


Suggestions


Please provide your valuable suggesstions here.

This Site is hosted on

Lunarpages.com Web Hosting