有没有办法使用对话框窗口来获取没有名称文件的文件夹路径?
答案 0 :(得分:40)
虽然是一个老问题,
我不喜欢那个丑陋的FolderBrowserDialog
,所以这里有一个对我有用的技巧,它使用SaveFileFolder
// 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
}
答案 1 :(得分:31)
// 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!
}
}