必要なのは質問だけだと思います。メソッドを Form.Load に配置しました。フォルダーを作成するか、SaveFileDialog を開くことができますが、両方を同時に開くことはできません。
誰かが私を助けてくれたらお願いします。ありがとう。
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);
}
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.
これは、新しいディレクトリを作成することです
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";