C# Exception:Access to the path "" is denied.

I add my project into VSS, and then program fire a exception like this---"Access to the path '' is denied". I don't know how to deal with it,so i search the problem in MSDN. But get nothing that can solute it.

原因有:1.有其它的程序正在使用要被覆盖的文件;

    2.用户的权限不够;

    看了很多地方都只有这两个原因的描述。也说了一些解决方案,但都不能解决我的问题。

    通过半天的找原因才发现,其中有一个文件是Read-only所以不让override。所以再加一条。

    3.文件是只读的;

    可以使用,Code:

FileInfo fi = new FileInfo("C:\\test.txt");

fi.Attributes = fi.Attributes & ~FileAttributes.ReadOnly & ~FileAttributes.Hidden

对文件的属性进行修改之后再用

File.Copy("D:\\test.txt", "C:\\test.txt" , true);

这样就能解决了!