Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 535 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I open Windows Explorer to a certain directory from within a WPF app?

#1
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:

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

Reply

#2
Why not `Process.Start(@"c:\test");`?
Reply

#3
You can use `System.Diagnostics.Process.Start`.

Or use the WinApi directly with something like the following, which will launch explorer.exe. You can use the fourth parameter to ShellExecute to give it a starting directory.


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);
}

The declarations come from the [pinvoke.net website][1].


[1]:

[To see links please register here]

Reply

#4
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.
Reply

#5
This should work:

Process.Start(@"<directory goes here>")
Or if you'd like a method to run programs/open files and/or folders:
```cs
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!
Reply

#6
Here's what worked for me:

Basically use the command line to call "start C:/path"
And exit the terminal afterward, so "start c:/path && exit"


```
WindowsExplorerOpen(@"C:/path");

public static void WindowsExplorerOpen(string path)
{
CommandLine(path, $"start {path}");
}

private static void CommandLine(string workingDirectory, string Command)
{
ProcessStartInfo ProcessInfo;
Process Process;

ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + Command + " && exit");
ProcessInfo.WorkingDirectory = workingDirectory;
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = true;
ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;

Process = Process.Start(ProcessInfo);
Process.WaitForExit();
}
```

Neither of these worked for me:

```
Process.Start(@"c:\test");
Process.Start("explorer.exe" , @"C:\Users");
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through