Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Folder Path with savefileDialog

Tags:

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

like image 429
Luca's Avatar asked Sep 07 '11 07:09

Luca's


People also ask

How do I use SaveFileDialog?

To save a file using the SaveFileDialog component. Display the Save File dialog box and call a method to save the file selected by the user. Use the SaveFileDialog component's OpenFile method to save the file. This method gives you a Stream object you can write to.

How to create Save file dialog box in c#?

SaveFileDialog(); DialogResult dr= saveFileDialog1. ShowDialog(); if (dr==DialogResult. OK) { string filename = saveFileDialog1. FileName; //save file using stream. }


2 Answers

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
}
like image 149
Sqrs Avatar answered Sep 17 '22 23:09

Sqrs


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!
    }
}
like image 28
WaltiD Avatar answered Sep 21 '22 23:09

WaltiD