Directory Browser Control?

jjjamie

Freshman
Joined
Aug 30, 2002
Messages
34
Location
England
Does anyone know where the directory browser control is in .NET? I can see the one that's there for compatability (DirListBox control) but it looks old. I need the one that looks like the FileSave dialog. Any ideas?
 
I have been searching the net high and low but I can only find examples for C#. Does anyone know of a way I can display a select folder dialog without having to make my own?
 
I posted a lengthy reply to this but it hasn't been copied across from the old forum (www.visualbasicforum.com). Thanks for your help guys.

[edit]Here you go - divil[/edit]

Thanks guys :)

I was looking at the source code and this is what I found:

Visual Basic:
Imports System.Windows.Forms

' This class is needed because the 
' System.Windows.Forms.Design.FolderNameEditor.FolderBrowser is Protected and thus 
' is not accessible in this context. Deriving a Public class from it enables you to
' use the dialog in your code.
Public Class FolderBrowser
	Inherits System.Windows.Forms.Design.FolderNameEditor

    Public Shared Function ShowDialog() As String
		Dim fb As New FolderBrowser()
        fb.Description = "Select a Directory to Scan"
        fb.Style = Design.FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem
        fb.ShowDialog()

        Return fb.DirectoryPath
    End Function
End Class

Why have Microsoft made the class protected? They have given no documentation on the FolderBrowser class. In the help files it says 'The FolderNameEditor.FolderBrowser type supports the .NET Framework infrastructure and is not intended to be used directly from your code.'.

I find this strange us I have seen a lot of people on forums asking how to create one. (Now I know the answer!)

Cheers.
 
Last edited by a moderator:
They want to discourage it as a user interface element I guess. The Visual Studio IDE uses an OpenFileDialog to select folders, I've noticed. It can actually make quite a good folder selection dialog, because when you turn off the display of files it becomes clear that folders are what you're selecting.
 
While I partially agree with what divil offered, I have to think that it's more of a tactic by Microsoft to leave functions that haven't been thoroughly tested undocumented. I don't blame them for doing so, as the framework is rather "young". I doubt divil or I can really back up either of our theories on the matter, but they certainly do make us wonder.
 
Hi...I am trying to sue this class in my application. But I cant find the FolderNameEditor in the Syste.Web.Forms.Design namespace. You were saying that we can write a public class if we want to use the Protected FolderNameEditor.FolderBrowser class. How can we do that?

Thanks,
SJ

jjjamie said:
I posted a lengthy reply to this but it hasn't been copied across from the old forum (www.visualbasicforum.com). Thanks for your help guys.

[edit]Here you go - divil[/edit]

Thanks guys :)

I was looking at the source code and this is what I found:

Visual Basic:
Imports System.Windows.Forms

' This class is needed because the 
' System.Windows.Forms.Design.FolderNameEditor.FolderBrowser is Protected and thus 
' is not accessible in this context. Deriving a Public class from it enables you to
' use the dialog in your code.
Public Class FolderBrowser
	Inherits System.Windows.Forms.Design.FolderNameEditor

    Public Shared Function ShowDialog() As String
		Dim fb As New FolderBrowser()
        fb.Description = "Select a Directory to Scan"
        fb.Style = Design.FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem
        fb.ShowDialog()

        Return fb.DirectoryPath
    End Function
End Class

Why have Microsoft made the class protected? They have given no documentation on the FolderBrowser class. In the help files it says 'The FolderNameEditor.FolderBrowser type supports the .NET Framework infrastructure and is not intended to be used directly from your code.'.

I find this strange us I have seen a lot of people on forums asking how to create one. (Now I know the answer!)

Cheers.
 
Yes, it is not fully tested in .NET 2003 version. It also contains some bugs. One of the bug I found is that if you path length really long then you get exception raise when getting the path length. It is unpredictable when it happened. Basically, I start getting error around 155 characters or above.
 
sorry to bring back an old topic like that but....

C:\Documents and Settings\Nicolas Dufour\Mes documents\Visual Studio Projects\HoraireInstaller\Form1.cs(589): The type or namespace name 'FolderNameEditor' does not exist in the class or namespace 'System.Windows.Forms.Design' (are you missing an assembly reference?)

I cant use the class... but i can run his exemple just fine, anyone can tell me what's wrong? maybe a part I didnt see?
i re-wrote the code in c# by the way so I might have missed something...
I included my code below so anyone chan chec what I did wrong...

Edit: Ok I just fond out... and I feel dumb... System.Windows.Forms.FolderBrowserDialog
so nevermind this
 
Last edited:
Back
Top