Sunday, 15 April 2012

c# - Response.WriteFile writing the webpage source instead of the text file -



c# - Response.WriteFile writing the webpage source instead of the text file -

when trying text file shared location , when user opens web browser not showing text file content , showing page source. how avoid that? doing wrong? here code. when run in local can able see text file info , getting page source too. english language bad sorry if there mistakes.

gridviewrow rw = (gridviewrow)(((linkbutton)e.commandsource).namingcontainer); linkbutton lnktxtfile = (linkbutton)rw.findcontrol("lnktxtfile"); string strfilename = lnktxtfile.text.replace("/","\\"); system.io.fileinfo targetfile = new system.io.fileinfo(strfilename); response.clear(); response.addheader("content-disposition", "attachment; filename=" + targetfile.name); response.contenttype = "application/octet-stream"; response.writefile(targetfile.fullname); httpcontext.current.applicationinstance.completerequest();

try replacing

httpcontext.current.applicationinstance.completerequest();

with

response.end();

c# response.write

No comments:

Post a Comment