Using the code below, I cannot show the open / save dialog as a file:
public void ProcessRequest(HttpContext context) { string link = context.Request.QueryString["Link"]; string extension = Path.GetExtension(link); string fileName = Path.GetFileName(link); string fullPath = String.Format("{0}\\{1}", context.Server.MapPath("~/Content/Uploads/"), fileName); if (File.Exists(fullPath)) { context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.AddHeader( "Content-Length", new FileInfo(fullPath).Length.ToString()); string contentType; switch (extension) { default: contentType = "application/octet-stream"; break; } context.Response.ContentType = contentType; context.Response.AddHeader( "Content-Disposition", String.Format("attachment; filename={0}", fileName)); context.Response.WriteFile(fullPath, true); context.Response.Flush(); } }
I tried to close the answer, leave the answer open, use TrasmitFile() , but I never get any dialogue or any feedback. I also tried debugging it, but no exceptions arise. Tried in IE 7/8 and Chrome. Any help is appreciated.
Thank!
The following is the output of Fiddler:
HTTP / 1.1 200 OK Cache-Control: private Content-Length: 3813 Content-Type: application / octet-stream Server: Microsoft-IIS / 7.5 Content-Disposition: affiliation; file name = b1af9b34-28cc-4479-a056-8c55b41a5ece.txt X-AspNet version: 4.0.30319 X-Powered-By: ASP.NET Date: Thu, 23 December 2010 21:51:58 GMT
* Home * Hotels * Reviews * Community * Travel Guide * Travel Insurance * Contact us
* FIDDLER: RawDisplay is truncated with 128 characters. Right-click to disable truncation. *
OO Dec 23 '10 at 21:25 2010-12-23 21:25
source share