답변:
ShowDialog를 호출하기 전에 SelectedPath 속성을 설정하기 만하면됩니다.
fdbLocation.SelectedPath = myFolder;
RootFolder . RootFolder가 설정된 경우 지정된 폴더와 그 아래에있는 모든 하위 폴더 만 대화 상자에 나타납니다. SelectedPath단지 주어진 경로를 미리 선택합니다.
ShowDialog를 호출하기 전에 SelectedPath 속성을 설정합니다.
folderBrowserDialog1.SelectedPath = @"c:\temp\";
folderBrowserDialog1.ShowDialog();
C : \ Temp에서 시작합니다.
SelectedPath is set to an absolute path that is a subfolder of RootFolder) 를 설정해야 합니까? 현재 동작 : C : \ Users \ Myusername \ Desktop을Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) 반환합니다 . 사용 로 가장 코드하는 것은 (로그온 유형 LOGON32_LOGON_INTERACTIVE 포함) 반환 빈 문자열을
fldrDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
"대화 상자를 표시하기 전에 SelectedPath 속성을 설정 한 경우 SelectedPath가 RootFolder의 하위 폴더 인 절대 경로로 설정되어 있으면이 경로가있는 폴더가 선택된 폴더가됩니다. RootFolder로 표시되는 쉘 네임 스페이스). "
"GetFolderPath 메서드는이 열거와 관련된 위치를 반환합니다. 이러한 폴더의 위치는 운영 체제마다 다른 값을 가질 수 있으며 사용자는 일부 위치를 변경할 수 있으며 위치는 지역화됩니다."
Re : Desktop 대 DesktopDirectory
데스크탑
"물리적 파일 시스템 위치가 아닌 논리적 데스크탑."
DesktopDirectory :
"데스크톱에 파일 개체를 물리적으로 저장하는 데 사용되는 디렉터리입니다.이 디렉터리를 가상 폴더 인 데스크톱 폴더 자체와 혼동하지 마십시오."
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) 반환합니다 . 가장 코드 (LogonType LOGON32_LOGON_INTERACTIVE 사용)를 사용하면 빈 문자열이
dotnet-snippets.de 에서 발견
리플렉션을 사용하면 실제 RootFolder가 작동하고 설정됩니다 !
using System;
using System.Reflection;
using System.Windows.Forms;
namespace YourNamespace
{
public class RootFolderBrowserDialog
{
#region Public Properties
/// <summary>
/// The description of the dialog.
/// </summary>
public string Description { get; set; } = "Chose folder...";
/// <summary>
/// The ROOT path!
/// </summary>
public string RootPath { get; set; } = "";
/// <summary>
/// The SelectedPath. Here is no initialization possible.
/// </summary>
public string SelectedPath { get; private set; } = "";
#endregion Public Properties
#region Public Methods
/// <summary>
/// Shows the dialog...
/// </summary>
/// <returns>OK, if the user selected a folder or Cancel, if no folder is selected.</returns>
public DialogResult ShowDialog()
{
var shellType = Type.GetTypeFromProgID("Shell.Application");
var shell = Activator.CreateInstance(shellType);
var folder = shellType.InvokeMember(
"BrowseForFolder", BindingFlags.InvokeMethod, null,
shell, new object[] { 0, Description, 0, RootPath, });
if (folder is null)
{
return DialogResult.Cancel;
}
else
{
var folderSelf = folder.GetType().InvokeMember(
"Self", BindingFlags.GetProperty, null,
folder, null);
SelectedPath = folderSelf.GetType().InvokeMember(
"Path", BindingFlags.GetProperty, null,
folderSelf, null) as string;
// maybe ensure that SelectedPath is set
return DialogResult.OK;
}
}
#endregion Public Methods
}
}
RootFolder로Environment.SpecialFolder.Desktop또는이 작동하지 않을 수 있습니다.