473,671 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Co mpatibility.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 55775
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******@annet site.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.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.Co mpatibility.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******@annet site.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.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.Co mpatibility.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.Fo lderNameEditor
Private objBrowse As New
System.Windows. Forms.Design.Fo lderNameEditor. FolderBrowser()

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

Function ShowDialog() As Windows.Forms.D ialogResult
Return objBrowse.ShowD ialog
End Function

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

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

Then you can call it with:

Dim objBrowse As New FolderBrowser(" Please select a folder")
If objBrowse.ShowD ialog = DialogResult.OK Then
msgbox ("You picked " & objBrowse.Direc toryPath)
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******@annet site.com> wrote in message news:e4******** ******@TK2MSFTN GP09.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.Co mpatibility.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.Fo lderNameEditor
Private objBrowse As New
System.Windows. Forms.Design.Fo lderNameEditor. FolderBrowser()

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

Function ShowDialog() As Windows.Forms.D ialogResult
Return objBrowse.ShowD ialog
End Function

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

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

Then you can call it with:

Dim objBrowse As New FolderBrowser(" Please select a folder")
If objBrowse.ShowD ialog = DialogResult.OK Then
msgbox ("You picked " & objBrowse.Direc toryPath)
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******@annet site.com> wrote in message news:e4******** ******@TK2MSFTN GP09.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.Co mpatibility.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******@annet site.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=folderbrows erdialog&lang=e n>

--
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******@annet site.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=folderbrows erdialog&lang=e n>

--
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******** ******@TK2MSFTN GP09.phx.gbl...
"Sakharam Phapale" <sp******@annet site.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=folderbrows erdialog&lang=e n>

--
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
2994
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 Connection object (OleDBConnection) will not Open (conIncident.Open) given the following situation: 1. Program is loaded and connection is established to Access database on C:
0
1023
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 = "*.lvl"; filedlg.ValidateNames = false;
4
28475
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 the last directory I opened a file in. Does anyone have any idea how I can fix this ?. Also is there any way to get the current path from where a program is being run from ?
0
564
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
1830
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 the OpenFileDialog, and select a txt file ( the file i select has nothing do with the database). When i try to update my dataset, It gives out
0
1181
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 on my form. Selected file path is written in to th TextBox. OpenFileDialog is open by click on a Button. There is other Button on the form run the code which save every form field to a file. When I manualy fill all fields in form everything...
5
4986
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 the path to a valid one in the FileOk-event and set the e.Cancel = true.
6
23129
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 drive and path?
2
4303
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 dir1/dir2/dir3/dir4/dir5/file.txt
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6222
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.