WebClient.FileDownlOad GIVIn错误文件a被其他进程访问

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

我正在尝试使用 webclient 方法下载文件 DownloadFile 但它给我的错误是

 The process cannot access the file '...\d915877c-cb7c-4eeb-97d8-41d49b75aa27.docx' because it is being used by another process.

但是当我通过单击打开文件时,它打开了。

有相同的问题要求相同的信息,但 none 已被接受。

任何帮助将不胜感激

可能是 oS 没有释放文件。不管是什么但是经过大量搜索后我找不到解决方案

这是创建文件的代码

  Document d = new Document();
  d.Save(HttpContext.Current.Server.MapPath(@"Invoice\" + iname + ".docx"));

我用的是aspose词dll

按照我访问它的方式

 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();
        }

顺便说一句,即使是不是使用代码创建的文件也会出现同样的错误。

给一个不同于下载源路径的下载文件保存路径。如果要替换文件,请在使用 File.replace() 方法处理 webclient 后执行此操作。

string downloadPath = "Your download path";      
string destinationPath = "the path where the file should be saved";`//this should be different from "download path"                   
 File.Download(downloadPath,destinationPath);