Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open an explorer window to browse a given UNC path using a WPF button or hyperlink?

I have a UNC path like \\machine\share\folder\something\ and I need to be able to open that location in windows explorer when a button is clicked. What WPF control should I use and how should I bind to that control from my viewModel?

An example of my viewModel is:

public class ViewModel : Screen {
    public string LogPath { get { return "\\machine\share\folder\something"; } }
}

I'm using Caliburn Micro, but I don't know if that's relevant.

like image 591
Byron Sommardahl Avatar asked Dec 29 '25 21:12

Byron Sommardahl


1 Answers

If I'm understanding your question properly, the use of WPF, Caliburn, etc is fairly irrelevant. You simply need a function on your ViewModel that runs the following code:

        Process.Start(new ProcessStartInfo
                      {
                          FileName = "\\\\machine\\share\\folder\\something",
                          UseShellExecute = true
                      });

I would use a simple Button control with a Command that is bound to your ViewModel, and potentially a CommandArgument to specify the path to launch if you need to.

like image 66
CodingGorilla Avatar answered Dec 31 '25 11:12

CodingGorilla