我试图在浏览器中打开文件(浏览器会给我打开/保存对话框)。这就是我正在使用的
FileStream MyFileStream = new FileStream(@"C:\bb.txt", FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "inline;attachment; filename=MyPDF.txt");
Response.BinaryWrite(Buffer);
它也正在将浏览器响应写入文件。我在网页上使用此代码,当它显示该文件时,浏览器也将Page Html也写入txt文件。
答案 0 :(得分:2)
添加Response.End()
答案 1 :(得分:0)
试试这个
Response.AppendHeader("Content-Disposition", "attachment; filename=YOurfilename.txt");