SharpSVN:进程无法访问该文件,因为它正由另一个进程使用

时间:2014-04-29 22:53:17

标签: .net svn add sharpsvn

我正在使用SharpSVN .NET库。仅在添加文件但未添加文件夹时才会发生此异常。为什么会这样?

Can't open file 'D:\FOLDER\FILE.xls': The process cannot access the file because it is being used by another process.

这是代码。它包含文件夹逻辑和文件逻辑。

        SvnUpdateArgs updateArgs2 = new SvnUpdateArgs();
        updateArgs2.Depth = SvnDepth.Empty;
        client.Update("D:\FOLDER", updateArgs2);

        if (!Directory.Exists("D:\FOLDER"))
        {
            System.IO.Directory.CreateDirectory("D:\FOLDER");

            SvnAddArgs addArgs1 = new SvnAddArgs();
            addArgs1.Depth = SvnDepth.Empty;
            client.Add("D:\FOLDER", addArgs1);

            SvnCommitArgs commitArgs1 = new SvnCommitArgs();
            commitArgs1.LogMessage = GeneralService.GetCurrentUserWindowsLogin();
            client.Commit("D:\FOLDER", commitArgs1);
        }

        // update if exists, otherwise add it to working copy if it does not exist

        SvnUpdateArgs updateArgs3 = new SvnUpdateArgs();
        updateArgs3.Depth = SvnDepth.Empty;
        client.Update("D:\FOLDER\FILE.xls", updateArgs3);

        if (!File.Exists("D:\FOLDER\FILE.xls"))
        {
            System.IO.File.Create("D:\FOLDER\FILE.xls");

            SvnAddArgs addArgs1 = new SvnAddArgs();
            addArgs1.Depth = SvnDepth.Empty;
            client.Add("D:\FOLDER\FILE.xls", addArgs1);

            SvnCommitArgs commitArgs1 = new SvnCommitArgs();
            commitArgs1.LogMessage = GeneralService.GetCurrentUserWindowsLogin();
            client.Commit("D:\FOLDER\FILE.xls", commitArgs1);
        }

1 个答案:

答案 0 :(得分:2)

当你使用system.io.file.create时,它会创建一个实例os system.io.stream因为它是一个共享函数。我想你可以用这样的简单方式修复它。

  Dim F As System.IO.FileStream = System.IO.File.Create("piipo")
  ''release the stream
    F.Close()