This is the code for downloading the file.
System.IO.FileStream fs = new System.IO.FileStream(Path+"\\"+fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte ar = new byte[(int)fs.Length]; fs.Read(ar, 0, (int)fs.Length); fs.Close(); Response.AddHeader("content-disposition", "attachment;filename=" + AccNo+".pdf"); Response.ContentType = "application/octectstream"; Response.BinaryWrite(ar); Response.End();
When this code is executed, it will ask user to open or save the file. Instead of this I need to open a new tab or window and display the file. How can I achieve this?
File won't necessary be located in the website folder. It might be located in an other folder.
Instead of loading a stream into a byte array and writing it to the response stream, you should have a look at HttpResponse.TransmitFile
Response.ContentType = "Application/pdf"; Response.TransmitFile(pathtofile);
If you want the PDF to open in a new window you would have to open the downloading page in a new window, for example like this:
<a href="viewpdf.aspx" target="_blank">View PDF</a>