C# 将字符串中的内容写入到流中,让客户端下载,但是在服务器端不形成文件
2个回答
展开全部
我给你一个例子,有点绕,主要是为了明白.
byte[] b = Encoding.Default.GetBytes("a");
MemoryStream ms = new MemoryStream(b);
BinaryReader br = new BinaryReader(ms);
b = ms.ToArray();
Response.AddHeader("Accept-Ranges", "bytes");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("adsf.txt", System.Text.Encoding.UTF8));
Response.BinaryWrite(b);
Response.End();
byte[] b = Encoding.Default.GetBytes("a");
MemoryStream ms = new MemoryStream(b);
BinaryReader br = new BinaryReader(ms);
b = ms.ToArray();
Response.AddHeader("Accept-Ranges", "bytes");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("adsf.txt", System.Text.Encoding.UTF8));
Response.BinaryWrite(b);
Response.End();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询