Reputation: 2118
I'm working on a ASP.NET website that allows users to download files.
Previously the files were stored on the same server as the website so we could do:
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.AddHeader("Content-Length", response.ContentLength.ToString());
Response.ContentType = "application/octet-stream";
Response.TransmitFile(path);
Response.End();
However, now some of the files are stored on a seperate server. I can verify that the files exist using
WebRequest request = WebRequest.Create(absolute-url);
WebResponse response = request.GetResponse();
But how can I facilitate the transfer as TransmitFile requires a virtual path not a url?
I need the users to be able to choose where to Save the file as with a normal web download
What's the best way to do this?
Upvotes: 3
Views: 11702
Reputation: 441
If you can get the response stream via a web request you should be able to copy the stream to your output stream as per this snippet:
while ((read = stream.Read(buffer, offset, chunkSize)) > 0)
{
Response.OutputStream.Write(buffer, 0, read);
Response.Flush();
}
Upvotes: 5
Reputation:
You can't use TransferFile for remote file. But you can use WriteFile for this.
Upvotes: 2
Reputation: 21178
You could map the drives of the remote servers as shares and then use TransmitFile. If the servers don't have line of sight you could enable WebDAV on the remote server(s) and then map them to a physical path and use TransmitFile.
Upvotes: 0
Reputation: 34573
Upvotes: 1