简体   繁体   中英

Opening file through Browser

I am trying to open the file in browser (browser will give me Open/Save dialog box). This is what I am using

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);

It is writing the browser response to the file also. I am using this code on a web page and when it is showing that file, browser also writing the Page Html also into the txt file.

添加Response.End()

尝试这个

 Response.AppendHeader("Content-Disposition", "attachment; filename=YOurfilename.txt");

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