I'm using this method to download a file from somewhere on my aspx page called: downloader.aspx

byte[] virtualPath = client.DownloadData(link/file.doc);
Response.BinaryWrite(virtualPath);

However, when the client shows the download it tells me: "Do you want to download downloader.doc from mywebsite.com? It does not show the original name.

Is there a way to use the original name (file.doc) instead of the name of the aspx page?

有帮助吗?

解决方案

Use the response header Content-Disposition to set the filename.

byte[] virtualPath = client.DownloadData(link/file.doc);
Response.AppendHeader("Content-Disposition", "attachment;filename=file.doc");
Response.BinaryWrite(virtualPath);

其他提示

You can use http response header field content dispostion. See https://stackoverflow.com/tags/content-disposition/info

Try the following

byte[] virtualPath = client.DownloadData(link/file.doc);
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" +"file.doc");
Response.BinaryWrite(virtualPath);
Response.End();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top