Accessing Desktop Folder from Code?
I'm writing an application in which the user can select files from a directory structure. My problem is that I only have the C: drive and a D: drive. I also need to be able to provide access to the "Desktop" directory structure. How can I add the Desktop directory structure to a "Directory" control? I basically need something like Windows Explorer.
Thanks,
Re: Accessing Desktop Folder from Code?
Code:
Environment.SpecialFolder.Desktop
See MSDN for a coding example and other special folders.
BB
Re: Accessing Desktop Folder from Code?
Another way:
My.Computer.FileSystem.SpecialDirectories.Desktop
Re: Accessing Desktop Folder from Code?
How do I include the "Desktop" structure in the DirectoryBox control?
Re: Accessing Desktop Folder from Code?
Quote:
Originally Posted by
blakemckenna
How do I include the "Desktop" structure in the DirectoryBox control?
What is a " DirectoryBox control"?
Did you mean this
Code:
Dim ofd As New OpenFileDialog
ofd.Multiselect = True
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim dr As DialogResult = ofd.ShowDialog
If dr = DialogResult.OK Then
For Each s As String In ofd.FileNames
Debug.WriteLine(s)
Next
End If
Re: Accessing Desktop Folder from Code?
My bad...I meant the "DirectoryListBox" control.
Re: Accessing Desktop Folder from Code?
Re: Accessing Desktop Folder from Code?
Yes...it originated in earlier versions of VB but you can include the namespace that contains the control. The namespace is "Microsoft.VisualBasic.Compatibility.VB6". Hope that helps!
Re: Accessing Desktop Folder from Code?
Oh. I got this far
Code:
Dim foo As New Microsoft.VisualBasic.Compatibility.VB6.DirListBox
'Warning(1) Microsoft.VisualBasic.Compatibility.VB6.DirListBox' is obsolete:
'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862'. C:\Users\dbasnett\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 11 24 WindowsApplication1
and stopped.
Re: Accessing Desktop Folder from Code?
Well...you can also add the control to the project on the toolbox. Look at the attached screenshot. Hope that helps!