質問

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