Reputation: 901
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.
Upvotes: 0
Views: 1744
Reputation: 4360
Try this
Response.AppendHeader("Content-Disposition", "attachment; filename=YOurfilename.txt");
Upvotes: 0