在我的应用程序中,用户可以下载自己的文件(图像、pdf、word、...)。我使用 HttpHandel 来做。开始选择文件并下载。我希望用户可以从列表中下载所有文件。怎么做?
public void ProcessRequest(HttpContext context) {
HttpResponse response = context.Response;
string cururl = context.Request.Url.ToString();
int iqs = context.Request.Url.ToString().IndexOf('?');
string querystring = (iqs < cururl.Length - 1) ? cururl.Substring(iqs + 1) : String.Empty;
NameValueCollection parameters = HttpUtility.ParseQueryString(querystring);
byte[] result = GetstreamForDownload(parameters);
string fileId = context.Request.QueryString["fileId"];
response.AddHeader("Content-disposition", "attachment; filename=" + GetFileName(parameters));
response.ContentType = "application/octet-stream";
response.BinaryWrite(result);
}