当我选择的文件夹位于远程服务器上并且是符号链接(symbolic link)(或任何类型的重新分析点)时,我遇到了 FolderBrowserDialog 的 SelectedPath 属性问题。
如果我选择普通文件夹,则会返回完整路径,例如“\SERVER\folder\subfolder\thing_I_clicked_on”。
但是,如果该文件夹是重新分析点,我只会得到“\SERVER\thing_I_clicked_on”(因此它缺少完整路径)
var dialog = new FolderBrowserDialog();
dialog.ShowDialog();
MessageBox.Show(dialog.SelectedPath);
有人遇到过这个问题或有什么建议吗?它似乎与权限无关,就好像我知道完整路径一样,我可以很高兴地浏览到它,等等。
最佳答案
因此,我对此进行了大量调查,并认为我有答案。
首先,对我所看到的进行一些解释!
在服务器 A 上,有一个共享包含指向服务器 B 上共享的符号链接(symbolic link):
\\serverA\Path\To\Folder
目标是
\\serverB\Folder
实际发生的情况是,从 FolderBrowserDialog.SelectedPath
返回的值是 \\serverB\Folder
,我误以为它缺少部分路径,因为字符串 serverA 和 serverB 非常相似!抱歉误导了大家。
我按照这个 MSDN Example 创建了自己的包装器并注意到 Shell32.dll 函数 SHGetPathFromIDList
正在返回重新分析点的目标,尽管文档说
If the pidl parameter specifies a shortcut, the pszPath will contain the path to the shortcut, not to the shortcut's target
我确实注意到之前的路径是正确的,所以在状态更改时的回调方法中,我捕获了未翻译的选定路径
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;
}
}
因此 SelectedFullPath
属性包含 \\serverA\Path\To\Folder
并且 SelectedPath
属性包含 \\ServerB\Folder
,这让我有很多工作要做。
关于c# - 具有重新分析点的 FolderBrowserDialog SelectedPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12282585/