c# - How to open PDF file in a new tab or window instead of downloading it (using asp.net)? -
this code downloading 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 code executed, ask user open or save file. instead of need open new tab or window , display file. how can achieve this?
note:
file won't necessary located in website folder. might located in other folder.
instead of loading stream byte array , writing response stream, should have @ httpresponse.transmitfile
response.contenttype = "application/pdf"; response.transmitfile(pathtofile);
if want pdf open in new window have open downloading page in new window, example this:
<a href="viewpdf.aspx" target="_blank">view pdf</a>
Comments
Post a Comment