I have an application that can be run from Explorer, and passes the selected directory to the application. So I can use the following code:
private void frmMain_Shown(object sender, EventArgs e)
{
//open the dir
DirectoryInfo d = new DirectoryInfo(cmdArgs);
SelectDirectoryInTree(d);
}
This however fails if the user selects a Special Folder. The path returned for these folders is different. So, for example, if the user selects Libraries\Documents
folder, (or any other folder in there) the returned DirectoryInfo is ::{xxxxx-xxxx-xxxxx-xxx-xxxxx}\Documents.library-ms
The specific exception:
System.ArgumentException: The path is not of a legal form.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.DirectoryInfo.Init(String path, Boolean checkHost)
at System.IO.DirectoryInfo..ctor(String path)
at FindIt.frmMain.frmMain_Shown(Object sender, EventArgs e) in d:\C#\+Other\FindIt\frmMain.cs:line 476
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
Whats the simplest way to get the correct folder supplied by the explorer shell?