简体   繁体   中英

Download a file that is written to the Response stream in ASP .NET C#

The objective: - Server side: Write a file to the response stream after verifying credentials. In other words, no public access to the file. - Client side: Download this file by from http://xyz.com?credentials=abc

So far, the ASPX page does the following:

  • Verify credentials
  • this.Response.ContentType = "application/octet-stream";
  • this.Response.BinaryWrite(binaryReader.ReadBytes(1024));

What is the best way to download this file data from a WinForms app?

The simplest approach would be to use WebClient :

WebClient wc = new WebClient();
wc.DownloadFile(url, filename);

(Either start this not in the UI thread, or use the async version. You don't want your UI thread to block while downloading.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM