c# - Why is the value null when using session variable -
c# - Why is the value null when using session variable -
i have asp.net website located in 1 of server , accessing site local pc on same network. when application runs, saves pdf file in c:\pdffolder
folder. want display link user can download file in local pc server.
i using session variable filename:
string strfilename = "completed_pdf_" + k + ".pdf"; //k variable within function session["filename"] = strfilename;
in server folder files stored is: c:\pdffolder\{filename}.pdf
local pc access file is: \\myserver\pdffolder\{filename}.pdf
the code download button is:
protected void downloadfile(object sender, eventargs e) { //messagebox.show(session["pathname"].tostring()); //messagebox.show(session["filename"].tostring()); messagebox.show(path.combine(@"c:\pdfgenerate", session["filename"].tostring()).tostring()); response.redirect("downloadfilepdf.ashx?myvar=" + session["filename"].tostring()); }
on button download file, fire httphandler
function onclick:
<%@ webhandler language="c#" class="downloadfilepdf" %> using system; using system.web; using system.io; public class downloadfilepdf : ihttphandler { public void processrequest (httpcontext context) { system.web.httprequest request2 = system.web.httpcontext.current.request; string strsessvar2 = request2.querystring["filename"]; system.web.httpresponse response = system.web.httpcontext.current.response; response.clearcontent(); response.clear(); response.contenttype = "application/pdf"; byte[] filebytearray = file.readallbytes(path.combine(@"c:\pdfgenerate", strsessvar2)); response.addheader("content-disposition", string.format("attachment; filename={0}.pdf", strsessvar2)); response.binarywrite(filebytearray); response.end(); } public bool isreusable { { homecoming false; } } }
i maintain getting error on line: byte[] filebytearray = file.readallbytes(path.combine(@"c:\pdfgenerate", strsessvar2));
the error is: value cannot null
how can prepare issue?
i believe issue line:
string strsessvar2 = request2.querystring["filename"];
you want value of myvar
:
string strsessvar2 = request2.querystring["myvar"];
c# asp.net pdf
Comments
Post a Comment