1

必要なのは質問だけだと思います。メソッドを Form.Load に配置しました。フォルダーを作成するか、SaveFileDialog を開くことができますが、両方を同時に開くことはできません。

誰かが私を助けてくれたらお願いします。ありがとう。

4

3 に答える 3

1

SaveFileDialog を使用すると、ユーザーは既存のファイルの場所を選択できます。そうでない場合は、@Bali が提案したように、ダイアログ内にフォルダーを作成できます。

ユーザーがダイアログを使用せずに新しいフォルダーを作成できるようにする場合は、ユーザーがパスを入力できるようにする必要があります (テキスト ボックスなど)。次に、 を使用してディレクトリが存在するかどうかを確認し、存在しDirectory.Existない場合は を使用して作成しDirectory.Createます。

void CheckPath(string path)
{
   var dir = Path.GetDirectoryName(path);
   if( !String.IsNullOrEmpty(dir) && !Directory.Exists(dir))
      Directory.Create(dir);
}
于 2012-06-07T16:37:11.473 に答える
1

Open a FolderBrowserDialog for the user with the title (Description property) set to something like "Choose an existing folder or create a new one". Do not forget to set its ShowNewFolderButton property to true.

You can also use the FolderBrowserDialog to ask the user only to select the containing ("parent") folder, and create the new folder yourself by calling Directory.CreateDirectory. In this case, ShowNewFolderButton should be false.

于 2012-06-07T16:31:57.610 に答える
0

これは、新しいディレクトリを作成することです

 Directory.CreateDirectory(@"C:\Your File Path Here");

これは、ファイルを開くことです。パスを変更することで、ファイルの初期ディレクトリを開く場所を選択できます。

 OpenFileDialog openFileDialog1 = new OpenFileDialog();
        openFileDialog1.InitialDirectory = (@"C:\Your starting File Path");
        openFileDialog1.Filter = "All Files (*.*)|*.*";
        openFileDialog1.Title = "Select a File";
于 2012-06-07T17:18:35.387 に答える