c# - How to download a file using ASP.NET -


in below code want download file local when click link button should download file specific path. in case throws

'c:/search/svgs/documents/img.txt' physical path, virtual path expected.

protected void lnkbtndoc_click(object sender, eventargs e) {     linkbutton lnkbtndoc = new linkbutton();     var searchdoc = session["filepath"];     string file = searchdoc.tostring();     response.addheader("content-disposition", "attachment;filename=\"" + file + "\"");     response.transmitfile(server.mappath(file));     response.end(); } 

use below code download file on link button click

<asp:linkbutton id="btndownload" runat="server" text="download"             onclick="btndownload_onclick" /> protected void btndownload_onclick(object sender, eventargs e)     {         string filename = "~/downloads/msizap.exe";         if (filename != "")         {             string path = server.mappath(filename);             system.io.fileinfo file = new system.io.fileinfo(path);             if (file.exists)             {                 response.clear();                 response.addheader("content-disposition", "attachment; filename=" + file.name);                 response.addheader("content-length", file.length.tostring());                 response.contenttype = "application/octet-stream";                 response.writefile(file.fullname);                 response.end();             }             else             {                 response.write("this file not exist.");             }         }     } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -