문제

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