我试图删除一个文件,但我得到错误消息(拒绝访问),即使我有完全的权限。最初我的文件将在我的根文件夹中。首先,我正在重命名该文件,然后将文件移动到另一个文件夹(在根文件夹之外),如下所示。在c中移动后无法删除文件#
System.IO.File.Move(strPhysicalFolder+ tpfile,strPhysicalFolder+fName);
System.IO.File.Move(strPhysicalFolder + fName, filePath + fName);
System.IO.File.SetAttributes(filePath + fName, FileAttributes.Normal);
现在,无论何时我尝试删除文件,我都会收到错误(拒绝访问)。 下面是我的代码:
string strFileFullPath = srcPath + filename;
if (System.IO.File.Exists(strFileFullPath))
{
System.IO.File.Delete(strFileFullPath);
}
strFileFullPath
包含路径到我无法删除的文件。在删除(设置属性)之前,我需要做些什么吗?任何帮助,将不胜感激。谢谢。
如果你去在资源管理器文件会发生什么。你真的可以从代码之外的新位置删除它吗? – Skintkingle
注意,但要查找'System.IO.Path.Combine()' –
没有足够的信息。你在移动和删除之间做什么?如果是这样:什么。另外:重命名和移动可以一步完成。另外:最好使用'System.IO.Path.Combine'的字符串连接。你确定所有路径都正确(包括路径分隔符)吗? – LocEngineer