开发者

Access denied to folder in one class but not another

开发者 https://www.devze.com 2023-02-07 04:51 出处:网络
I get an exception when trying the rename a folder with this code: Directory.Move(@\"D:\\MyOldFolderName\", @\"D:\\MyNewFolderName\");

I get an exception when trying the rename a folder with this code:

Directory.Move(@"D:\MyOldFolderName", @"D:\MyNewFolderName");

The exception:

System.IO.IOException was unhandled
  Message="Access to the path 'D:\\MyOldFolderName' is denied."
  Source="mscorlib"
  StackTrace:
     at S开发者_StackOverflowystem.IO.Directory.Move(String sourceDirName, String destDirName)
     ...

The thing is, the EXACT same codeline works in another class of my application. The application only consist of one single DLL.

What is happening here? Any ideas?

More info:

  • The application is a WPF application, using the MVVM design pattern.
  • The class where the folder rename DOES work is a ViewModel.
  • The class where the folder rename does NOT work is a helper class (the method does some database related stuff before trying to rename the folder).


This is probably not due to rights but to the fact that somewhere in the code you're opening files/streams from those folders... put a breakpoint before you try to move the folder and examine that folder with some tool like Who Lock Me or similar to see are there any differences when the first class does it, and the second one... I would expect that just before you try to move the folder with the 'failing' class the folder you're moving is locked (in use)...

0

精彩评论

暂无评论...
验证码 换一张
取 消