Frage

I would like to set the InitialDirectory property of a WindowsAPICodePack CommonOpenFileDialog to My computer Location, I did it using the equivalent CLSID or GUID or what the hell is that, just I would like to know if exist a more native/safe way to correctly set the My computer location, I've tried this but didn't worked:

.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) 

This is the code that I'm using:

Dim FolderPicker As New Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog

With FolderPicker

    .IsFolderPicker = True
    .Title = "Folder Dialog Test"
    .InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ' My Computer
    .DefaultFileName = "C:\"

End With

UPDATE:

I'm on Windows 8 x64.

The other special folders such as libraries and desktop works like this:

.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) 
War es hilfreich?

Lösung

Environment.GetFolderPath never returns a path for MyComputer since there isn't actually a path for it.

From the MSDN documentation:

The MyComputer constant always yields the empty string ("") because no path is defined for the My Computer folder.

This means that your solution is the best available (and likely one that not too many people are aware of). For future interest, here is a link to the list of available CLSIDs.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top