public static string GetPathFromWindowsExplorer(string dialogtitle = "Select file path strength.") { try { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2048]); // 存放目录路径缓冲区 ofn2.lpszTitle = dialogtitle; // 标题 ofn2.ulFlags = 0x00000040; // 新的样式,带编辑框 IntPtr pidlPtr = SHBrowseForFolder(ofn2); char[] charArray = new char[2048]; for (int i = 0; i < 2048; i++) { charArray[i] = '\0'; } SHGetPathFromIDList(pidlPtr, charArray); string res = new string(charArray); res = res.Substring(0, res.IndexOf('\0')); return(res); } catch (Exception e) { Debug.LogError(e); } return(string.Empty); }
private static extern IntPtr SHBrowseForFolder([In, Out] OpenDialogDir ofn);