Select Folder Path with savefileDialog

前端 未结 2 1794
耶瑟儿~
耶瑟儿~ 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: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
    }
    

提交回复
热议问题