如何克服这个错误。访问路径“C:\Documents and Settings”被拒绝。 [英] how to overcome this error. Access to the path 'C:\Documents and Settings' is denied.
问题描述
我正在编写以下代码。它将显示一个错误,如下所示错误
拒绝访问路径''C:\Documents and Settings''。如何纠正这个错误。
private void button1_Click( object sender,EventArgs e)
{
foreach (字符串文件 GetFiles( C:\\))
{
// Console.WriteLine(file);
listBox2.Items.Add(file);
}
}
static IEnumerable< string> GetFiles( string 路径)
{
Queue< string> queue = new 队列< string>();
queue.Enqueue(path);
while (queue.Count > 0 )
{
path = queue.Dequeue();
尝试
{
foreach ( string subDir in Directory.GetDirectories(path))
{
queue.Enqueue(subDir);
}
}
catch (Exception ex)
{
MessageBox.Show( ex);
Console.Error.WriteLine(ex);
}
string [] files = null ;
尝试
{
files = Directory.GetFiles(path);
}
catch (例外情况)
{
Console.Error.WriteLine(ex);
}
if (files!= null )
{
for ( int i = 0 ;我< files.Length; i ++)
{
yield < span class =code-keyword> return files [i];
}
}
}
}
< blockquote>文档和设置文件夹称为 Junction点 [ ^ ]。这就是它抛出异常的原因。
来自MSDN:
Quote:这些连接点可以标识如下:
•它们设置了FILE_ATTRIBUTE_REPARSE_POINT,FILE_ATTRIBUTE_HIDDEN和FILE_ATTRIBUTE_SYSTEM文件属性。
•它们还设置了访问控制列表(ACL)拒绝对每个人的读取权限。
看看这个MSDN Environment.SpeciaFolder枚举 [ ^ ]
祝你好运,
OI
您好,
您是否可以手动浏览该位置。请检查您是否拥有此位置的完全访问权限''C:\Documents and Settings''以执行任何读取或写入操作。
i am writing bellow code . it will shows one error that error is bellow
Access to the path ''C:\Documents and Settings'' is denied. how to rectify this error.
private void button1_Click(object sender, EventArgs e)
{
foreach (string file in GetFiles("C:\\"))
{
// Console.WriteLine(file);
listBox2.Items.Add(file);
}
}
static IEnumerable<string> GetFiles(string path)
{
Queue<string> queue = new Queue<string>();
queue.Enqueue(path);
while (queue.Count > 0)
{
path = queue.Dequeue();
try
{
foreach (string subDir in Directory.GetDirectories(path))
{
queue.Enqueue(subDir);
}
}
catch (Exception ex)
{
MessageBox.Show("ex");
Console.Error.WriteLine(ex);
}
string[] files = null;
try
{
files = Directory.GetFiles(path);
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
if (files != null)
{
for (int i = 0; i < files.Length; i++)
{
yield return files[i];
}
}
}
}
Documents and settings folder is known as a "Junction Point[^]". That''s why it is throwing that exception.
From MSDN:
Quote:These junction points can be identified as follows:
•They have the FILE_ATTRIBUTE_REPARSE_POINT, FILE_ATTRIBUTE_HIDDEN, and FILE_ATTRIBUTE_SYSTEM file attributes set.
•They also have their access control lists (ACLs) set to deny read access to everyone.
Have a look at this MSDN Environment.SpeciaFolder Enumeration[^]
Good luck,
OI
Hi,
Are you able to browse through that location manually. Please check you got full access permission for this location ''C:\Documents and Settings'' to perform any read or write operation.
这篇关于如何克服这个错误。访问路径“C:\Documents and Settings”被拒绝。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!