Belgeler dizini ve alt dizinlerine erişmeye çalışıyorum ancak her defasında erişim reddedildi. Ben İstisna bkz:C# - Console Uygulamasında reddedilen dizine erişim
benim kodudur - Ben çalışıyorum bütün Bu dizinin toplam boyutunu almak.System.UnauthorizedAccessException: yol Erişim 'C: \ Users \ MyUser Belgelerim \ Müziğim \' engellendi İşte
class Program
{
static void Main(string[] args)
{
try {
// Make a reference to a directory.
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
DirectoryInfo di = new DirectoryInfo(path);
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles(".", SearchOption.AllDirectories);
// Display the names and sizes of the files.
Console.WriteLine("The directory {0} contains the following files:", di.Name);
long size = 0;
foreach (FileInfo f in fiArr)
{
size += f.Length;
size++;
}
Console.WriteLine("The size of desktop files." + size);
}
catch(Exception e)
{
Console.WriteLine("Exceptions {0}" , e);
}
}
}
bir ağ sürücüsünün kapalı bu uygulamayı çalıştırıyor musunuz? Öyleyse, davranış değişip değişmediğini görmek için masaüstüne kopyalamayı deneyin. – Cameron
Bunu görmüyorsanız, kodunuza da bakmak istemezsiniz. Bu bir * hard link *, bir dizin değil. DirectoryInfo.Attributes kullanın, Sistem veya ReparsePoint özniteliği olan her şeyden uzak durun. Ejderhalar orada yaşıyor. –
Bu özel klasörü kullanmak, sizin için en iyi seçenek olmayabilir. Bu soruyu kontrol edin, http://stackoverflow.com/questions/14560884/windows-user-profile-path-folders – Nikki9696