I have a text
file in my local drive. I want to show the content of it in a new tab.
I have tried the following
1st Try
string fileName = @"C:\MyFile.log";
Page.ClientScript.RegisterStartupScript(GetType(), "windowKey", "window.open('" + fileName + "');", true);
2nd Try
Response.Write("<script>");
Response.Write("window.open('C:\\MyFile.log', '_newtab');");
Response.Write("</script>");
Both of these open in new tab but the data inside the file is not displaying
After some search, I found this
FileStream MyFileStream = new FileStream(@"C:\MyFile.log", FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "inline; filename=sample.txt");
Response.BinaryWrite(Buffer);
This is displaying the content in my file but along with that it is also displaying my aspx
page
So my question is how to show a text file in a new tab