IT박스

WPF 앱 내에서 특정 디렉토리로 Windows 탐색기를 열려면 어떻게해야합니까?

itboxs 2020. 6. 20. 10:38
반응형

WPF 앱 내에서 특정 디렉토리로 Windows 탐색기를 열려면 어떻게해야합니까?


WPF 응용 프로그램에서 사용자가 버튼을 클릭하면 Windows 탐색기를 특정 디렉토리로 열고 싶습니다. 어떻게합니까?

나는 다음과 같은 것을 기대할 것이다.

Windows.OpenExplorer("c:\test");

왜 안돼 Process.Start(@"c:\test");?


이것은 작동해야합니다 :

Process.Start(@"<directory goes here>")

또는 프로그램을 실행하거나 파일 및 / 또는 폴더를 여는 방법을 원할 경우 :

        private void StartProcess(string path)
    {
        ProcessStartInfo StartInformation = new ProcessStartInfo();

        StartInformation.FileName = path;

        Process process = Process.Start(StartInformation);

        process.EnableRaisingEvents = true;
    }

그런 다음 메소드를 호출하고 괄호 안에 파일 및 / 또는 폴더의 디렉토리 또는 응용 프로그램 이름을 입력하십시오. 이것이 도움이 되었기를 바랍니다!


사용할 수 있습니다 System.Diagnostics.Process.Start.

또는 WinApi를 다음과 같이 직접 사용하면 explorer.exe가 시작됩니다. ShellExecute에 네 번째 매개 변수를 사용하여 시작 디렉토리를 지정할 수 있습니다.

public partial class Window1 : Window
{
    public Window1()
    {
        ShellExecute(IntPtr.Zero, "open", "explorer.exe", "", "", ShowCommands.SW_NORMAL);
        InitializeComponent();
    }

    public enum ShowCommands : int
    {
        SW_HIDE = 0,
        SW_SHOWNORMAL = 1,
        SW_NORMAL = 1,
        SW_SHOWMINIMIZED = 2,
        SW_SHOWMAXIMIZED = 3,
        SW_MAXIMIZE = 3,
        SW_SHOWNOACTIVATE = 4,
        SW_SHOW = 5,
        SW_MINIMIZE = 6,
        SW_SHOWMINNOACTIVE = 7,
        SW_SHOWNA = 8,
        SW_RESTORE = 9,
        SW_SHOWDEFAULT = 10,
        SW_FORCEMINIMIZE = 11,
        SW_MAX = 11
    }

    [DllImport("shell32.dll")]
    static extern IntPtr ShellExecute(
        IntPtr hwnd,
        string lpOperation,
        string lpFile,
        string lpParameters,
        string lpDirectory,
        ShowCommands nShowCmd);
}

선언은 pinvoke.net 웹 사이트에서 제공 됩니다.


Process.Start("explorer.exe" , @"C:\Users");

I had to use this, the other way of just specifying the tgt dir would shut the explorer window when my application terminated.

참고URL : https://stackoverflow.com/questions/1746079/how-can-i-open-windows-explorer-to-a-certain-directory-from-within-a-wpf-app

반응형