c# - Generic handler file download does not start -


i'm trying start downloading files server, hardcoded values files exists reason download not start , no error thrown.

this code have:

public void processrequest(httpcontext context) {     string destpath = context.server.mappath("~/attachments/cover.txt");     // check see if file exist     fileinfo fi = new fileinfo(destpath);      if (fi.exists)     {         httpcontext.current.response.clearheaders();         httpcontext.current.response.clearcontent();         httpcontext.current.response.appendheader("content-length", fi.length.tostring());         httpcontext.current.response.contenttype = "application/octet-stream";         httpcontext.current.response.appendheader("content-disposition", "attachment; filename=" + "cover.txt");         httpcontext.current.response.binarywrite(readbytearryfromfile(destpath));         httpcontext.current.response.end();     } }  public bool isreusable {         {         return false;     } }  private byte[] readbytearryfromfile(string destpath) {     byte[] buff = null;     filestream fs = new filestream(destpath, filemode.open, fileaccess.read);     binaryreader br = new binaryreader(fs);     long numbytes = new fileinfo(destpath).length;     buff = br.readbytes((int)numbytes);     return buff; } 

i'm stepping in code , no problem occuring no file download popup shown in browser.

do guys see wrong?

thanks in advance, laziale

i believe issue having calling httpcontext.current. since utilizing generic handler file believe you'll want utilize context parameter being passed method signature. example be:

public void processrequest (httpcontext context) {      // build document , zip:      buildandzipdocument();        // context:      context.response.contenttype = "application/zip";      context.response.addheader("content-disposition", "filename="commodity.zip");      zip.save(context.response.outputstream);       // close:      context.response.end(); } 

i believe if utilize context, rather httpcontext.current resolve issue.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -