Question

I am using a meta refresh tag to point to a file that i want to download from a server. How do i make it so that it downloads all files, rather than opens them in the browser. I am adding the meta tag in code behind like this:

String filename = filenode.Element("name").Value.ToString();
HtmlMeta redirectMetaTag = new HtmlMeta();
redirectMetaTag.HttpEquiv = "Refresh";
redirectMetaTag.Content = string.Format("2;url=http://example.example.net/example/" + filename);
this.Header.Controls.Add(redirectMetaTag);

At the moment, thie file eg a jpg is just being opened in the browser

No correct solution

OTHER TIPS

If you want to force the browser to open a Save As dialog you must add a couple of custom headers for the page.

I sugggest you to use the TransmitFile function:

Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=[your-file-name]");
Response.TransmitFile( Server.MapPath("~/images/[your-file-name]") );
Response.End();

It will automatically write the file content to the OutputStream of the Response.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top