Windows Develop Bookmark and Share   
 index > Windows Forms General > Can OpenFileDialog be used to obtain a path?
 

Can OpenFileDialog be used to obtain a path?

Can I use OpenFileDialog to obtain a path, not a file?

In the Installer class of a Windows Console program, I want the user to open a dialog box to specify a folder where the application program can create files later. Is it doable? How if so? Thank you very much!
gardener01  Saturday, November 05, 2005 4:52 AM
 gardener01 wrote:
Thanks. However, since my application is a console application, I cannot use System.Windows.Forms. How can I solve the problem?


Although your application is a console application, you can still add a reference to System.Windows.Forms.dll, which will enable you to use the FolderBrowserDialog.

Also if you are able to use the OpenFileDialog dialog, then you can use the FolderBrowserDialog also as they are contained in the same assembly (System.Windows.Forms.dll).
David M. Kean  Sunday, November 06, 2005 12:36 AM
Have a look at the following thread which explains why this could be happening:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=10245&SiteID=1.
David M. Kean  Sunday, November 06, 2005 10:21 PM
No, but .NET 1.1 introduced the FolderBrowserDialog.
Daniel Rieck  Saturday, November 05, 2005 5:47 AM
Thanks. However, since my application is a console application, I cannot use System.Windows.Forms. How can I solve the problem?
gardener01  Saturday, November 05, 2005 5:56 AM

ok, if you cannot use WinForm, there's not other way as let the user enter the path string by himself...

Konstantin Gonikman  Saturday, November 05, 2005 12:07 PM
 gardener01 wrote:
Thanks. However, since my application is a console application, I cannot use System.Windows.Forms. How can I solve the problem?


Although your application is a console application, you can still add a reference to System.Windows.Forms.dll, which will enable you to use the FolderBrowserDialog.

Also if you are able to use the OpenFileDialog dialog, then you can use the FolderBrowserDialog also as they are contained in the same assembly (System.Windows.Forms.dll).
David M. Kean  Sunday, November 06, 2005 12:36 AM

Hi, I use the FolderBrowserDialog in installer class. However, when the dialog box is open, I did not see anywhere where a user can select a folder. Using MessageBox, I saw folder_browser_dialog.RootFolder = "personal". It does not looks like a path. What is the problem here? Or FolderBrowserDialog cannot be used in installer class? Please help me. Many many thanks. Below is the code.

FolderBrowserDialog folder_browser_dialog = new System.Windows.Forms.FolderBrowserDialog();

folder_browser_dialog.Description = "Select the directory that you want to use to create tickler letters.";

folder_browser_dialog.RootFolder = Environment.SpecialFolder.Personal;

MessageBox.Show(folder_browser_dialog.RootFolder.ToString(), "");

DialogResult result = folder_browser_dialog.ShowDialog();

if( result == DialogResult.OK )

folderName = folder_browser_dialog.SelectedPath;

gardener01  Sunday, November 06, 2005 2:42 AM
Have a look at the following thread which explains why this could be happening:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=10245&SiteID=1.
David M. Kean  Sunday, November 06, 2005 10:21 PM

You can use google to search for other answers

Custom Search

More Threads

• Printer Driver in Longhorn
• RichTextBox again
• How to specify TextBox overflow truncation direction?
• Justifying Text
• EventHandlers for dynamically created controls.
• Drawing on notifyicon fails
• DataGridView Unhighlight
• How to print the total number of pages on each page?
• TreeView Sorting Problem (.NET 2.0)
• Windows shortcut issue