By: Paul S. Cilwa | Viewed: 12/7/2023 Posted: 8/21/2018 |
Page Views: 616 | |
Topics: #Computers #CustomBrowser #KnownFolders #Organica #Programming #VB.NET | |||
How to create a class to encapsulate the Known Folders of Windows Vista+. |

Windows has had "special" folders since Windows 95. You remember the Documents folder, right? As well as Desktop, and (with later versions of Windows) Downloads, My Music, and so forth.
With Windows Vista, this conglomerate of folders became known officially as "Known Folders", despite there being no "unknown folders" to speak of.
Most, but not all, of the Known Folders are accessible to VB.NET programs via a simple function call. But to package them all in a class solution allows for even simpler access in any application that needs it.
Here's the new class module, KnownFolders.vb:
KnownFolders.vb
Imports System.IO
Public Class KnownFolders
Public Shared ReadOnly Property Desktop() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property MyProfile() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property Favorites() As FileInfo
Get
Dim Path As String = CreateObject("WScript.Shell").Specialfolders(15)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property MyDocuments() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property MyMusic() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property MyPictures() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
Return New FileInfo(Path)
End Get
End Property
Public Shared ReadOnly Property MyVideos() As FileInfo
Get
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)
Return New FileInfo(Path)
End Get
End Property
End Class