对一个类中的文件夹的访问被拒绝,但对另一类中的文件夹的访问则不然
尝试使用以下代码重命名文件夹时出现异常:
Directory.Move(@"D:\MyOldFolderName", @"D:\MyNewFolderName");
例外:
System.IO.IOException was unhandled
Message="Access to the path 'D:\\MyOldFolderName' is denied."
Source="mscorlib"
StackTrace:
at System.IO.Directory.Move(String sourceDirName, String destDirName)
...
问题是,完全相同的代码行在我的应用程序的另一个类中工作。该应用程序仅包含一个 DLL。
这里发生了什么?有什么想法吗?
更多信息:
- 该应用程序是一个 WPF 应用程序, 使用MVVM设计模式。
- 文件夹重命名的类 ViewModel 确实有效。
- 文件夹重命名的类 不起作用的是一个辅助类( 方法做一些与数据库相关的事情 在尝试重命名之前的东西 文件夹)。
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 System.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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不是由于权限,而是因为在代码中的某个位置您正在从这些文件夹打开文件/流...在尝试移动文件夹并使用诸如 谁锁定我 或类似的内容,看看第一堂课和第二堂课时是否有任何差异。 ..我希望在您尝试移动具有“失败”类的文件夹之前,您要移动的文件夹已被锁定(正在使用)...
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)...