How can I open Windows Explorer to a certain directory from within a WPF app?

前端 未结 4 562
执笔经年
执笔经年 2020-12-02 08:11

In a WPF application, when a user clicks on a button I want to open the Windows explorer to a certain directory, how do I do that?

I would expect something like this

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 08:54

    This should work:

    Process.Start(@"")
    

    Or if you'd like a method to run programs/open files and/or folders:

    private void StartProcess(string path)
    {
        ProcessStartInfo StartInformation = new ProcessStartInfo();
    
        StartInformation.FileName = path;
    
        Process process = Process.Start(StartInformation);
    
        process.EnableRaisingEvents = true;
    }
    

    And then call the method and in the parenthesis put either the directory of the file and/or folder there or the name of the application. Hope this helped!

提交回复
热议问题