-
Apr 1st, 2009, 10:42 AM
#1
Thread Starter
Junior Member
-
Apr 1st, 2009, 11:01 AM
#2
Re: FolderBrowserDialog
try this:
vb Code:
Dim fbd As New FolderBrowserDialog
Dim type As Type = fbd.[GetType]
'======== Get Fieldinfo for rootfolder.
Dim fieldInfo As Reflection.FieldInfo = type.GetField("rootFolder", _
Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
'========= Now set the value for Folder Dialog using DirectCast
'=== 18 = Network Neighborhood is the root
fieldInfo.SetValue(fbd, DirectCast(18, Environment.SpecialFolder))
fbd.ShowDialog()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 1st, 2009, 11:01 AM
#3
Re: FolderBrowserDialog
You know, you would think they would just add the stupid flags in there for you to that enum... Since they don't you have to get a little creative.
Since you are using VS2008, you can use extension methods, to extend functionality of existing classes.
So lets make an extension method to add a SetRootFolder sub routine to the folderbrowsedialog class.
You do this by adding a module to your project, then add this code:
Code:
Imports System
Imports System.Reflection
Imports System.Runtime.CompilerServices
Module FolderBrowserExtensions
<Extension()> _
Public Sub SetRootFolder(ByVal fbd As System.Windows.Forms.FolderBrowserDialog, ByVal SpecialFolder As SpecialFoldersEx)
Dim t As Type = fbd.[GetType]()
Dim fi As FieldInfo = t.GetField("rootFolder", BindingFlags.Instance Or BindingFlags.NonPublic)
fi.SetValue(fbd, DirectCast(SpecialFolder, System.Environment.SpecialFolder))
End Sub
<Flags()> _
Public Enum SpecialFoldersEx
Desktop = &H0
' Desktop
Internet = &H1
' Internet Explorer (icon on desktop)
Programs = &H2
' Start Menu\Programs
Controls = &H3
' My Computer\Control Panel
Printers = &H4
' My Computer\Printers
Personal = &H5
' My Documents
Favorites = &H6
' user name\Favorites
Startup = &H7
' Start Menu\Programs\Startup
Recent = &H8
' user name\Recent
SendTo = &H9
' user name\SendTo
BitBucket = &HA
' desktop\Recycle Bin
StartMenu = &HB
' user name\Start Menu
MyDocuments = &HC
' logical "My Documents" desktop icon
MyMusic = &HD
' "My Music" folder
MyVideo = &HE
' "My Videos" folder
DesktopDirectory = &H10
' user name\Desktop
Drives = &H11
' My Computer
Network = &H12
' Network Neighborhood (My Network Places)
Nethood = &H13
' user name\nethood
Fonts = &H14
' windows\fonts
Templates = &H15
CommonStartMenu = &H16
' All Users\Start Menu
CommonPrograms = &H17
' All Users\Start Menu\Programs
CommonStartup = &H18
' All Users\Startup
CommonDesktopDirectory = &H19
' All Users\Desktop
AppData = &H1A
' user name\Application Data
PrintHood = &H1B
' user name\PrintHood
LocalAppData = &H1C
' user name\Local Settings\Applicaiton Data (non roaming)
AltStartup = &H1D
' non localized startup
CommonAltStartup = &H1E
' non localized common startup
CommonFavorites = &H1F
InternetCache = &H20
Cookies = &H21
History = &H22
CommonAppdata = &H23
' All Users\Application Data
Windows = &H24
' GetWindowsDirectory()
System = &H25
' GetSystemDirectory()
ProgramFiles = &H26
' C:\Program Files
MyPictures = &H27
' C:\Program Files\My Pictures
Profile = &H28
' USERPROFILE
SystemX86 = &H29
' x86 system directory on RISC
ProgramFilesX86 = &H2A
' x86 C:\Program Files on RISC
ProgramFilesCommon = &H2B
' C:\Program Files\Common
ProgramFilesCommonx86 = &H2C
' x86 Program Files\Common on RISC
CommonTemplates = &H2D
' All Users\Templates
CommonDocuments = &H2E
' All Users\Documents
CommonAdminTools = &H2F
' All Users\Start Menu\Programs\Administrative Tools
AdminTools = &H30
' user name\Start Menu\Programs\Administrative Tools
Connections = &H31
' Network and Dial-up Connections
CommonMusic = &H35
' All Users\My Music
CommonPictures = &H36
' All Users\My Pictures
CommonVideo = &H37
' All Users\My Video
Resources = &H38
' Resource Direcotry
ResourcesLocalized = &H39
' Localized Resource Direcotry
CommonOemLinks = &H3A
' Links to All Users OEM specific apps
CdBurnArea = &H3B
' USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
ComputersNearMe = &H3D
' Computers Near Me (computered from Workgroup membership)
FlagCreate = &H8000
' combine with CSIDL_ value to force folder creation in SHGetFolderPath()
FlagDontVerify = &H4000
' combine with CSIDL_ value to return an unverified folder path
FlagNoAlias = &H1000
' combine with CSIDL_ value to insure non-alias versions of the pidl
FlagPerUserInit = &H800
' combine with CSIDL_ value to indicate per-user init (eg. upgrade)
FlagMask = &HFF00
End Enum
End Module
Then in your form, you can simple use this:
Code:
Using FBD As New FolderBrowserDialog
FBD.SetRootFolder(SpecialFoldersEx.Network)
FBD.ShowDialog(Me)
'MORE CODE HERE
End Using
-
Apr 1st, 2009, 11:06 AM
#4
Re: FolderBrowserDialog
considering it looks like Paul and I came up with the exact same solution (just implemented differently), and I found the reflection trick via google. I will assume he did too
So just as a side tip, most answers are already on the web
-
Apr 1st, 2009, 11:07 AM
#5
Re: FolderBrowserDialog
yep. you caught me. i googled it
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 1st, 2009, 11:10 AM
#6
Re: FolderBrowserDialog
no harm in that of course. It just goes to show really that many answers are already available, and its a matter of knowing how to look for them. I googled it too.
It is not like I never have questions and know all things about programming. I just tend to not need to ask questions on here because I usually find my answer before it gets to the point of needing to ask.
-
Apr 1st, 2009, 11:50 AM
#7
Thread Starter
Junior Member
Re: FolderBrowserDialog
Thanks guys.
This is exactly what i was looking for
I also found this :
http://www.codeproject.com/KB/dotnet...k_Folders.aspx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|