Edw*_*uay 140 c# wpf windows-explorer
在WPF应用程序中,当用户单击某个按钮时,我想将Windows资源管理器打开到某个目录,我该怎么做?
我希望这样的事情:
Windows.OpenExplorer("c:\test");
Run Code Online (Sandbox Code Playgroud)
Jam*_*ney 291
为什么不Process.Start(@"c:\test");
呢?
Ant*_*yth 13
这应该工作:
Process.Start(@"<directory goes here>")
Run Code Online (Sandbox Code Playgroud)
或者,如果您想要一种运行程序/打开文件和/或文件夹的方法:
private void StartProcess(string path)
{
ProcessStartInfo StartInformation = new ProcessStartInfo();
StartInformation.FileName = path;
Process process = Process.Start(StartInformation);
process.EnableRaisingEvents = true;
}
Run Code Online (Sandbox Code Playgroud)
然后调用方法并在括号中放置文件和/或文件夹的目录或应用程序的名称.希望这有帮助!
Abe*_*bel 11
你可以用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);
}
Run Code Online (Sandbox Code Playgroud)
声明来自pinvoke.net网站.
Process.Start("explorer.exe" , @"C:\Users");
Run Code Online (Sandbox Code Playgroud)
我必须使用它,另一种仅指定tgt dir的方法将在应用程序终止时关闭资源管理器窗口。
归档时间: |
|
查看次数: |
124103 次 |
最近记录: |