Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# documentBuilder:进程无法访问该文件,因为其他进程正在使用该文件_C#_Asp.net_Filesystems_Openxml_Openxml Sdk - Fatal编程技术网

C# documentBuilder:进程无法访问该文件,因为其他进程正在使用该文件

C# documentBuilder:进程无法访问该文件,因为其他进程正在使用该文件,c#,asp.net,filesystems,openxml,openxml-sdk,C#,Asp.net,Filesystems,Openxml,Openxml Sdk,我正在使用DocumentBuilder(OpenXMLAPI),对于那些不了解DocumentBuilder的人,我将给出一个简短的解释:它有一个函数“BuildDocument”,它获取源列表(每个源包含wmldocument)和要保存到的文件名字符串 public static void BuildDocument(List<Source> sources, string fileName) 但是,当我在服务器上运行我的项目时,我不断收到错误:“该进程无法访问该文件,

我正在使用DocumentBuilder(OpenXMLAPI),对于那些不了解DocumentBuilder的人,我将给出一个简短的解释:它有一个函数“BuildDocument”,它获取源列表(每个源包含wmldocument)和要保存到的文件名字符串

    public static void BuildDocument(List<Source> sources, string fileName)
但是,当我在服务器上运行我的项目时,我不断收到错误:“该进程无法访问该文件,因为它正被另一个进程使用。” 好几次都可以。在visualStudio中,它也可以正常工作。
有什么问题吗

文档文件可能已打开。

保存保存的文件后,检查其是否已正确关闭。如果不是,那么下次尝试打开文件并向其中添加文本时,可能会出现错误。使用类似于
File.Close()

的东西好的,我发现了我的错误,它在我的代码中,而不是在DocumentBuilder中。 我写道:

我没有关上它。我必须将代码更改为: FileInfo f=新文件信息。。。。 FileStream fs=f.Create(); fs.Close();
谢谢你们所有人愿意帮助我!!!我真的很感激

您是否使用同一个流来打开和写入它?(您可能需要将更多与打开、读取和写入此文件相关的代码放入其中。)问题可能在于调用
BuildDocument
方法的地方。有可能得到这部分代码吗?当然有:file.close()!!!我没有写构建文档的代码。我想这是微软提供的:file.close(),当然!!!我没有写构建文档的代码。我想这是微软的一件事,检查一下是否有任何与权限相关的问题。
    File.WriteAllBytes(...)
    FileInfo f=new FileInfo....
    f.Create();