473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to use OpenFileDialog control to select directory path.

Hi All,

I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.

How to make it possible?

I tried it using "VisualBasic.Compatibility.VB6.DirListBox" control, but it
does not work properly.

It has following two properties,

1.SelectedItem :- which returns just folder name.

2.Path :- which always return application path

It should return path of the selected folder, but seems to be not working.

Any solution?

Thanks in Advance

Sakharam Phapale


Nov 21 '05 #1
7 55748
Hi,

Use the folder browser dialog instead. The control is included with
vs.net 2003 here is a link to a vs.net 2002 version.

http://www.windowsforms.com/Samples/...113&tabindex=4

Ken
-------------------------
"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.

How to make it possible?

I tried it using "VisualBasic.Compatibility.VB6.DirListBox" control, but it
does not work properly.

It has following two properties,

1.SelectedItem :- which returns just folder name.

2.Path :- which always return application path

It should return path of the selected folder, but seems to be not working.

Any solution?

Thanks in Advance

Sakharam Phapale

Nov 21 '05 #2
Hi,

Use the folder browser dialog instead. The control is included with
vs.net 2003 here is a link to a vs.net 2002 version.

http://www.windowsforms.com/Samples/...113&tabindex=4

Ken
-------------------------
"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.

How to make it possible?

I tried it using "VisualBasic.Compatibility.VB6.DirListBox" control, but it
does not work properly.

It has following two properties,

1.SelectedItem :- which returns just folder name.

2.Path :- which always return application path

It should return path of the selected folder, but seems to be not working.

Any solution?

Thanks in Advance

Sakharam Phapale

Nov 21 '05 #3
If you have VB.NET 2003, you can use the BrowseForFolder dialog to do that. Otherwise, you have to do this:
Copied from a post by :Anthony Glenwright.

In VB, create a class:

Public Class FolderBrowser
Inherits System.Windows.Forms.Design.FolderNameEditor
Private objBrowse As New
System.Windows.Forms.Design.FolderNameEditor.Folde rBrowser()

Sub New(ByVal Text As String)
MyBase.New()
objBrowse.Description = Text
End Sub

Function ShowDialog() As Windows.Forms.DialogResult
Return objBrowse.ShowDialog
End Function

Property Text() As String
Get
Return objBrowse.Description
End Get
Set(ByVal Value As String)
objBrowse.Description = Text
End Set
End Property

ReadOnly Property DirectoryPath() As String
Get
Return objBrowse.DirectoryPath
End Get
End Property
End Class

Then you can call it with:

Dim objBrowse As New FolderBrowser("Please select a folder")
If objBrowse.ShowDialog = DialogResult.OK Then
msgbox ("You picked " & objBrowse.DirectoryPath)
End If

This worked for me until I upgraded to VB.NET 2003. Then the BrowseForFolder Dialog control was added. But, this one works just
fine.
james
"Sakharam Phapale" <sp******@annetsite.com> wrote in message news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.

How to make it possible?

I tried it using "VisualBasic.Compatibility.VB6.DirListBox" control, but it
does not work properly.

It has following two properties,

1.SelectedItem :- which returns just folder name.

2.Path :- which always return application path

It should return path of the selected folder, but seems to be not working.

Any solution?

Thanks in Advance

Sakharam Phapale

Nov 21 '05 #4
If you have VB.NET 2003, you can use the BrowseForFolder dialog to do that. Otherwise, you have to do this:
Copied from a post by :Anthony Glenwright.

In VB, create a class:

Public Class FolderBrowser
Inherits System.Windows.Forms.Design.FolderNameEditor
Private objBrowse As New
System.Windows.Forms.Design.FolderNameEditor.Folde rBrowser()

Sub New(ByVal Text As String)
MyBase.New()
objBrowse.Description = Text
End Sub

Function ShowDialog() As Windows.Forms.DialogResult
Return objBrowse.ShowDialog
End Function

Property Text() As String
Get
Return objBrowse.Description
End Get
Set(ByVal Value As String)
objBrowse.Description = Text
End Set
End Property

ReadOnly Property DirectoryPath() As String
Get
Return objBrowse.DirectoryPath
End Get
End Property
End Class

Then you can call it with:

Dim objBrowse As New FolderBrowser("Please select a folder")
If objBrowse.ShowDialog = DialogResult.OK Then
msgbox ("You picked " & objBrowse.DirectoryPath)
End If

This worked for me until I upgraded to VB.NET 2003. Then the BrowseForFolder Dialog control was added. But, this one works just
fine.
james
"Sakharam Phapale" <sp******@annetsite.com> wrote in message news:e4**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.

How to make it possible?

I tried it using "VisualBasic.Compatibility.VB6.DirListBox" control, but it
does not work properly.

It has following two properties,

1.SelectedItem :- which returns just folder name.

2.Path :- which always return application path

It should return path of the selected folder, but seems to be not working.

Any solution?

Thanks in Advance

Sakharam Phapale

Nov 21 '05 #5
"Sakharam Phapale" <sp******@annetsite.com> schrieb:
I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.


Displaying the dialog for choosing a directory
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=folderbrowserdialog&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
"Sakharam Phapale" <sp******@annetsite.com> schrieb:
I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.


Displaying the dialog for choosing a directory
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=folderbrowserdialog&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
Thanks All,
Sakharam Phapale
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
"Sakharam Phapale" <sp******@annetsite.com> schrieb:
I want to give option to user for selecting directory, just like for
selecting file using OpenFileDialog control.


Displaying the dialog for choosing a directory
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=folderbrowserdialog&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jody Gelowitz | last post by:
VS.NET 2002 and 2003 are installed. ..NET Framework 1.0 and 1.1 installed Program running under VisualBasic.NET 2002 with .NET Framwork 1.0 I am experiencing a problem with ADO.NET where the...
0
by: QQ | last post by:
I have the following code : OpenFileDialog filedlg = new OpenFileDialog(); filedlg.InitialDirectory = directory.Text; filedlg.Filter = "lvl files (*.lvl)|*.lvl" ; filedlg.FileName =...
4
by: Eps | last post by:
I have a problem that is driving me crazy, I have and openfiledialog but I can't seem to set its initial path. I have the initalDirecotry property set to the correct path but it always opens at...
0
by: Sakharam Phapale | last post by:
Hi All, I want to give option to user for selecting directory, just like for selecting file using OpenFileDialog control. How to make it possible?
3
by: Jon | last post by:
Hi, I am scratching all my hair out and really have no idea what is happening with my program... I have a dataset, and i used dataAdapter to fill the data. Everything works fine until I run...
0
by: Gregaz | last post by:
I have a form in my project, which I open as a DialogBox. On that that form there are 3 TextBoxes. To one of them I want to write in a file path. To have it easier I have an OpenFileDialog control...
5
by: =?Utf-8?B?UGVy?= | last post by:
I want to change the current path in the OpenFileDialog in runtime. When the user presses OK-button I'm checking the selected path if it's valid for my application. If it's not valid I want to set...
6
by: SpreadTooThin | last post by:
After I select a file with the OpenFileDialog, I get the file name with .FileName, but I want to know the drive and path where that file is. What function, method, class can I use in C# to get the...
2
by: Peted | last post by:
Hi i have a circumstance where a user unzips a file, with a certain layer of directories to get to a textfile. So in any directory on the HDD they may end up with something like ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.