无法打开目录“mydocuments”在Windows 10上,C# [英] Can't open directory "mydocuments" on windows 10, C#

查看:295
本文介绍了无法打开目录“mydocuments”在Windows 10上,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我尝试打开目录MyDocuments,但它在Windows 10上不起作用。为什么以及如何解决问题?



private void button1_Click(object sender,EventArgs e)

{

FolderBrowserDialog fbd = new FolderBrowserDialog();

fbd.RootFolder = System.Environment.SpecialFolder.MyDocuments;

if(fbd.ShowDialog()== System.Windows.Forms.DialogResult.OK)

MessageBox.Show(fbd.SelectedPath);





}



提前致谢

Merh



我的尝试:



Hi

I try to open the directory "MyDocuments" but it dosen't work on windows 10. Why and how can I solve the problem?

private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = System.Environment.SpecialFolder.MyDocuments;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(fbd.SelectedPath);


}

Thanks in advance
Merh

What I have tried:

private void button1_Click(object sender, EventArgs e)
{
      FolderBrowserDialog fbd = new FolderBrowserDialog();
      fbd.RootFolder = System.Environment.SpecialFolder.MyDocuments;
       if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            MessageBox.Show(fbd.SelectedPath);
          

}

推荐答案

叹息....它有助于阅读有关什么的文档你正在使用而不只是假设你知道它做了什么。



Environment.SpecialFolder是一个枚举。一组数值,指的是一组众所周知的概念。在这种情况下,MyDocuments的值为5,而不是文件夹的路径。



如果您阅读 SpecialFolder [ ^ ],你会看到它明确地说:

GetFolderPath方法返回与此枚举关联的位置。这些文件夹的位置在不同的操作系统上可以有不同的值,用户可以更改一些位置,并且位置已本地化。



你必须使用Environment.GetFolderPath()来获取文件夹的实际路径:

Sigh.... It helps to read the documentation on what you're using instead of just assuming you know what it does.

Environment.SpecialFolder is an enumeration. A set of numerical values that refers to a "well-known" set of concepts. In this case, MyDocuments has the value of 5, not the path to the folder.

If you read the documentation on SpecialFolder[^], you'll see that it sepcifically says:
The GetFolderPath method returns the locations associated with this enumeration. The locations of these folders can have different values on different operating systems, the user can change some of the locations, and the locations are localized.

You have to use Environment.GetFolderPath() to get the actual path to the folder:
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


这篇关于无法打开目录“mydocuments”在Windows 10上,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆