如何删除asp.net中的只读文件夹,c#
我想删除只读文件夹。我确实喜欢这个如何删除asp.net中的只读文件夹,c#,asp.net,Asp.net,我想删除只读文件夹。我确实喜欢这个 //Remove Read-only for the Folder File.SetAttributes(folderpath, File.GetAttributes(folderpath) & ~FileAttributes.ReadOnly); //Delete Folder FileInfo myfileinf = new FileInfo(folderpath); myfileinf.Delete(); 但是我
//Remove Read-only for the Folder
File.SetAttributes(folderpath, File.GetAttributes(folderpath) & ~FileAttributes.ReadOnly);
//Delete Folder
FileInfo myfileinf = new FileInfo(folderpath);
myfileinf.Delete();
但是我得到了这个错误
“对路径“E:\Working Folder\RPEssential\RPEssential\ResourcePlus PL\RDLReports\t”的访问被拒绝”。拒绝只读的原因可能有很多。文件夹正在使用中吗?在控制台中打开?运行可执行文件?所有这些你都应该检查一下。即使它有权限,如果目录正在使用中,它也不允许您删除它。正如我之前评论的,问题是您在删除文件时试图删除文件夹 您应该使用Directory.Delete方法删除文件夹 在下面的链接中,有一个关于如何使用它的好例子
运行ASP.NET应用程序池的用户必须具有删除该文件夹的适当权限。希望如此helps@juanreyesv但是管理员已经手动设置了权限alreadyTry,删除只读标志并执行代码。它是否工作?@Sachin如果您试图删除整个文件夹,则应使用目录。删除此项。
public static void Main()
{
// Specify the directories you want to manipulate.
string path = @"c:\MyDir";
string subPath = @"c:\MyDir\temp";
try
{
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
// Create the directory.
Directory.CreateDirectory(path);
}
if (!Directory.Exists(subPath))
{
// Create the directory.
Directory.CreateDirectory(subPath);
}
// This will succeed because subdirectories are being deleted.
Console.WriteLine("I am about to attempt to delete {0}", path);
Directory.Delete(path, true);
Console.WriteLine("The Delete operation was successful.");
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}