【问题标题】:The process cannot access the file in web services进程无法访问 Web 服务中的文件
【发布时间】:2013-03-12 06:05:17
【问题描述】:

以下是我在删除目录时从网络服务获得的异常

The process cannot access the file 'button.js' because it is being used by another process. 
3/22/2013 11:16:51 AM : Exception :The process cannot access the file 'button.js'   because it is being used by another process.

内部异常:

堆栈跟踪:

在 System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive) 在 System.IO.Directory.Delete(字符串 fullPath,字符串 userPath,布尔递归) 在 System.IO.Directory.Delete(字符串路径,布尔递归) 在 E:\websites\test.cont.com\CRMobileAPI\v5_2\apibridge.asmx.cs:line 1213 中的 CRMobileAPI.v5_2.apibridge.downloadcompleted(String userid, String deviceid, String filepathurl)

来源:

mscorlib

这是我的代码,

               if (Directory.Exists(_DirPath))
                {
                    try
                    {                            
                        DirectoryInfo _DirTemp = new DirectoryInfo(_DirPath);
                        _DirTemp.Delete(true);
                    }
                    catch (Exception Ex)
                    {
                        clsExHandler.Instance.Write(Ex);
                    }
                }

注意:此异常不仅适用于“button.js”,而且会随时间变化。

我该如何解决这个问题;我的记录器文件遇到了这个异常。

【问题讨论】:

    标签: c#-4.0 iis-7.5 fileinfo directoryinfo


    【解决方案1】:

    很可能的原因是,文件正在使用中。您必须确保 Web 服务器没有访问该文件。但是,没有标准的方法可以做到这一点。

    我建议您处理此异常并在稍有延迟后重试删除文件。 Web 服务器通常会在很短的时间内访问该文件,它应该会很快释放它,因此如果您使用相同的文件重试,则很有可能成功删除它。

    【讨论】:

    • 您应该首先准备一份您要删除的所有文件和目录的列表。看看这个 - stackoverflow.com/questions/3710617/…。 - 稍后您可以遍历每个单独的文件并将其删除。进行第二遍并删除第一遍中未删除的那些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多