c# - WebClient.FileDownlOad GIVIn error that the file a is accessed by another process -


i trying download file using webclient method downloadfile giving me error that

 process cannot access file '...\d915877c-cb7c-4eeb-97d8-41d49b75aa27.docx' because being used process. 

but when open file clicking it, opening.

there same question requesting same info none accepted answers.

any appreciated

it may os not letting file go. whatever after searching lot unable find solution

here code create file

  document d = new document();   d.save(httpcontext.current.server.mappath(@"invoice\" + iname + ".docx")); 

i using aspose word dll

and following way accessing it

 using (var client = new system.net.webclient())         {              client.usedefaultcredentials = true;             client.downloadfile(server.mappath("invoice/" + request.querystring["id"].tostring() + ".docx"),server.mappath("invoice/" +request.querystring["id"].tostring() + ".docx"));             client.dispose();         } 

and btw giving same error files not creaated using code.

give different path save download file different download source path. if want replace file after disposing webclient using file.replace() method.

string downloadpath = "your download path";       string destinationpath = "the path file should saved";`//this should different "download path"                     file.download(downloadpath,destinationpath); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -