c# - Force a hyperlink to open in a new window using context.Response -
i have web page having links pdf files, e.g. http://www.someurl.com/somefolder/filename.pdf.
when user clicks on these links, authentication kicks in, user logs in , file can downloaded. i'm trying achieve downloads open in new window.
i have limited access/control code , can't put target=_blank
attribute href or add javascript. code downloads after authentication below:
string filename = path.getfilename(context.request.physicalpath); filestream myfilestream; long filesize; string strmappath = context.server.mappath(filename); myfilestream = new filestream(strmappath, filemode.open); filesize = myfilestream.length; //allocate size our buffer array byte[] buffer = new byte[(int)filesize]; myfilestream.read(buffer, 0, (int)filesize); myfilestream.close(); //do buffer cleanup context.response.buffer = true; context.response.clear(); //add appropriate headers context.response.addheader("content-disposition", "attachement filename=" + filename); //add right contenttype context.response.contenttype = "application/pdf"; //stream out via binary write context.response.binarywrite(buffer);
can possibly force context.response
open in new window?
opening new window client side action whereas context.response
server side command. open new window need on client side.
if can't change original page source run script or alter html want can't done. on request return page has script open new window wouldn't same. you'd either have recreate original page entirely except added script (and if can assume change original page) or you'd have different page opens popup.
the solution change original page add popup script either target="_blank"
or script adds onclick handler link. both of these can't do.
Comments
Post a Comment