Select Folder Path with savefileDialog

前端 未结 2 1780
耶瑟儿~
耶瑟儿~ 2020-12-31 05:23

Is there a way to using a dialog window to get the folder path without name file?

相关标签:
2条回答
  • 2020-12-31 05:52

    Check the FolderBrowserDialog

    // Bring up a dialog to chose a folder path in which to open or save a file.
    private void folderMenuItem_Click(object sender, System.EventArgs e)
    {
        var folderBrowserDialog1 = new FolderBrowserDialog();
    
        // Show the FolderBrowserDialog.
        DialogResult result = folderBrowserDialog1.ShowDialog();
        if( result == DialogResult.OK )
        {
            string folderName = folderBrowserDialog1.SelectedPath;
            ... //Do your work here!
        }
    }
    
    0 讨论(0)
  • 2020-12-31 05:53

    Though an old question,

    I didn't like that uglyFolderBrowserDialog, so here's a trick that worked for me, it uses the SaveFileDialog

    // Prepare a dummy string, thos would appear in the dialog
    string dummyFileName = "Save Here";
    
    SaveFileDialog sf = new SaveFileDialog();
    // Feed the dummy name to the save dialog
    sf.FileName = dummyFileName;
    
    if(sf.ShowDialog() == DialogResult.OK)
    {
        // Now here's our save folder
        string savePath = Path.GetDirectoryName(sf.FileName);
       // Do whatever
    }
    
    0 讨论(0)
提交回复
热议问题