62,041
社区成员
发帖
与我相关
我的任务
分享
WebClient wb = new WebClient( );
byte[] bytes = wb.DownloadData(attachFullName);
this._context.Response.Clear();
this._context.Response.BufferOutput = true;
this._context.Response.Buffer = false;
this._context.Response.Charset = "GB2312";
this._context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//通知浏览器下载文件而不是打开
//this._context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(attCName, System.Text.Encoding.UTF8));
this._context.Response.AddHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(attCName, System.Text.Encoding.UTF8));
string fileType = attCName.EndsWith("txt") == true ? "txt" : attCName.EndsWith("pdf") == true ? "pdf" : attCName.EndsWith("doc") == true ? "word" : "pdf";
switch (fileType)
{
case "pdf":
{
this._context.Response.ContentType = "application/pdf";
break;
}
case "word":
{
this._context.Response.ContentType = "application/msword";
break;
}
case "txt":
default:
{
this._context.Response.ContentType = "text/plain";
break;
}
}
//this._context.Response.ContentType = "application/octet-stream";
this._context.Response.BinaryWrite(bytes);
this._context.Response.Flush( );
this._context.Response.Close( );