Pergunta

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?

Foi útil?

Solução

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);

Outras dicas

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();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top