Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FolderBrowserDialog SelectedPath with reparse points

I'm having issues with the SelectedPath property of the FolderBrowserDialog when the folder I select is on a remote server and is a symbolic link (or any kind of reparse point).

If i select a normal folder, then I get the full path returned, for example "\SERVER\folder\subfolder\thing_I_clicked_on".

However, if the folder is a reparse point, i get just "\SERVER\thing_I_clicked_on" (so it's missing the full path)

var dialog = new FolderBrowserDialog();
dialog.ShowDialog();
MessageBox.Show(dialog.SelectedPath);

Anyone come across this or have any suggestions? It doesn't appear to be permissions related, as if I know the full path i can quite happily browse to it, etc.

like image 891
Andy Irving Avatar asked Sep 05 '12 13:09

Andy Irving


2 Answers

so, I've been investigating this quite a lot, and think i have an answer.

First, a bit of explanation about what I was seeing!

on server A, there is a share which contains a symbolic link to a share on server B:

\\serverA\Path\To\Folder

and the target of that is

\\serverB\Folder

What was actually happening was, the value returned from FolderBrowserDialog.SelectedPath was \\serverB\Folder, and I was mistakenly thinking it was missing parts of the path, because the strings serverA and serverB are very similar! Sorry for misleading everyone.

I created my own wrapper following this MSDN Example and noticed that the Shell32.dll function SHGetPathFromIDList is returning the Target of the reparse point, despite the fact that the documentation says

If the pidl parameter specifies a shortcut, the pszPath will contain the path to the shortcut, not to the shortcut's target

I did notice that the path before that is the correct one though, so in my callback method when the status changed, I captured the untranslated selected path

private int FolderBrowserCallback(IntPtr hwnd, int msg, IntPtr lParam, IntPtr lpData)
        {
            switch (msg)
            {
                 case BrowseForFolderMessages.BffmSelchanged:
                     if (haveValidPath && !String.IsNullOrEmpty(displayedPath))
                                {
                                    if (IntPtr.Zero != _hwndEdit)
                                    {
                                        SelectedFullPath = displayedPath;
                                    }
        }

So the SelectedFullPath Property contains \\serverA\Path\To\Folder and SelectedPath property contains \\ServerB\Folder, which leaves me a lot to work with.

like image 189
Andy Irving Avatar answered Oct 06 '22 20:10

Andy Irving


How do I programmatically access the target path of a windows symbolic link must be here. Are you sure that you need exactly full path, not path to reparse point? I think you can use this path instead. "Notethat Windows does not support junctions to directories on remote shares." proof

like image 25
cdmnk Avatar answered Oct 06 '22 19:10

cdmnk