-1

OpenFileDialog を使用してアプリケーションのフォルダをすばやく開くにはどうすればよいですか?

        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
           ...........

        }
4

2 に答える 2

6

Guessing that you mean "Show the OpenFileDialog starting in my application's folder", just set the OpenFileDialog.InitialDir to your application's folder before showing the OpenFileDialog.

string AppPath = Path.GetDirectoryName(Application.ExecutablePath);;
openFileDialog1.InitialDir = AppPath;

If you need help finding your application's directory, see Getting root folder of application

于 2012-12-03T23:27:42.963 に答える
2

Use the FileDialog.InitialDirectory Property if you wish to override one of the default ways for its value getting set (described on MSDN).

openFileDialog1.InitialDirectory = @"C:\";  // based on comment of question
于 2012-12-03T23:26:49.827 に答える