c# - access to the path 'c:\windows\system32\inetsrv\dotnetzip-uxoebj5p.tmp' is denied -


i trying save zip file web api throwing exception :

access path 'c:\windows\system32\inetsrv\dotnetzip-uxoebj5p.tmp'  denied.   @ system.io.__error.winioerror(int32 errorcode, string  maybefullpath) @ system.io.filestream.init(string path, filemode mode, fileaccess access,  int32 rights, boolean userights, fileshare share, int32 buffersize,  fileoptions options, security_attributes secattrs, string msgpath, boolean  bfromproxy, boolean uselongpath, boolean checkhost) 

at system.io.filestream..ctor(string path, filemode mode, fileaccess access, fileshare share, int32 buffersize, fileoptions options, string msgpath, boolean bfromproxy @ system.io.filestream..ctor(string path, filemode mode) @ ionic.zip.sharedutilities.createandopenuniquetempfile(string dir, stream& fs, string& filename) @ ionic.zip.zipfile.get_writestream() @ ionic.zip.zipfile.save() @ archnies.archnies.downloadfile(string url)

code :

            logger.logmessage("downloading file url " + url);             // construct http request file             httpwebrequest httprequest = (httpwebrequest)webrequest.create(url);             httprequest.cookiecontainer = new system.net.cookiecontainer();              (int = 0; <= driver.manage().cookies.allcookies.count - 1; i++)             {                 system.net.cookie ck = new system.net.cookie(driver.manage().cookies.allcookies[i].name, driver.manage().cookies.allcookies[i].value, driver.manage().cookies.allcookies[i].path, driver.manage().cookies.allcookies[i].domain);                 httprequest.cookiecontainer.add(ck);             }             string useragent = (string)((ijavascriptexecutor)driver).executescript("return navigator.useragent;");             httprequest.accept = "text/html, application/xhtml+xml, */*";             httprequest.useragent = useragent;// "mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) gecko";              //httpstatuscode responsestatus;             // http response web server             httpwebresponse httpresponse = (httpwebresponse)httprequest.getresponse();             stream httpresponsestream = httpresponse.getresponsestream();              //  define buffer , buffer size             int buffersize = 1024;             byte[] buffer = new byte[buffersize];             int bytesread = 0;              // read response , write file             string userprofile = configurations.appdatapath; //environment.getfolderpath(environment.specialfolder.userprofile);             byte[] b = null;              using (memorystream ms = new memorystream())             {                 int count = 0;                                 {                     byte[] buf = new byte[1024];                     //count = stream.read(buf, 0, 1024);                     count = httpresponsestream.read(buf, 0, 1024);                     ms.write(buf, 0, count);                 } while (httpresponsestream.canread && count > 0);//while (stream.canread && count > 0);                 b = ms.toarray();             }             string filename = path.combine(userprofile, string.format("archaniesreport{0}.zip", new random().next(512365412)));             logger.logmessage("file: " + filename);             zipfile zip = new zipfile();             zip.addentry(filename, b);              zip.save(path.getfilename(filename));             zip.dispose();             using (filestream filestream = file.create(filename))             {                 while ((bytesread = httpresponsestream.read(buffer, 0, buffersize)) != 0)                 {                     filestream.write(buffer, 0, bytesread);                 }             }             file.copy(path.getfilename(filename), filename, true);             return true; 

i tried

 zip.tempfilefolder = configurations.appdatapath; 

but doesn't seem fix problem.

kindly , let me know

you can download file temporary location, using path.gettemppath() (msdn). after download complete, can move file file.copy(...) user's folder , delete file temp file.delete(...).

using approach won't acces denied exception.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -