asp.net mvc 4 - Download file in Zip -


i want download file in zip,but got error code , regarding error bellow

my code:

        using (zipfile zip = new zipfile())         {              zip.alternateencodingusage = zipoption.asnecessary;             zip.adddirectorybyname("files");             //foreach (gridviewrow row in gridview1.rows)             //{             //    if ((row.findcontrol("chkselect") checkbox).checked)             //    {             //        string filepath = (row.findcontrol("lblfilepath") label).text;             //        zip.addfile(filepath, "files");             //    }             //}             directoryinfo directory = new directoryinfo(server.mappath(@"~\election\latur"));             var files = directory.getfiles().tolist();                             foreach (var file in files)             {                 zip.addfile(file.tostring(),"files");             }             response.clear();             response.bufferoutput = false;             string zipname = string.format("zip_{0}.zip", datetime.now.tostring("yyyy-mmm-dd-hhmmss"));             response.contenttype = "application/zip";             response.addheader("content-disposition", "attachment; filename=" + zipname);             zip.save(response.outputstream);             response.end();         } 

when using above code download file in zip follwing error occure

error

enter image description here

there 2 possible cause of error:

1- directory "files" not possible create(denied permission) 2- not possible obtain files "~\election\latur"

anyway lines: var files = directory.getfiles().tolist();
foreach (var file in files)

the type var think not correct this. string base64 coder more correct.


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -