Monday, October 24, 2005

Forcing File Downloads

In C# (ASP.NET) it’s just as simple:

private void Page_Load(object sender, System.EventArgs e)
{
// Disable caching this page (C#)
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Buffer = true;
Response.ContentType = "application/binary";
Response.AppendHeader("Content-Disposition: attachment; " +
filename=dlimg.png");
Response.WriteFile(Server.MapPath("images/dlimg.png");
Response.End();
}

No comments: