質問

With folderBrowseDialog you can show the top level of the folder which will be shown initially. However that feature is not there on openFileDialog.

I want to let the user open files from a specific folder only. How do I specify the folder?

役に立ちましたか?

解決

Just set the openFileDialog.InitialDirectory

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = @"C:\";
openFileDialog.ShowDialog();

他のヒント

Set InitialDirectory property:

OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = @"D:\SomeFolder";
dialog.ShowDialog();

Gawjus, answering your question "How can I restrict the user from accessing other folders? can I lock them?", you can use Environment Special Folder as per code below, but as far I know you cannot define a custom folder, there are some options available. Another way it's to create an UserControl that list only files from a specific folder. Doing that you can have more control how it will behave.

ofd.RootFolder = Environment.SpecialFolder.MyDocuments;

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top