现在的位置: 首页 > 综合 > 正文

C#执行”打开”操作

2014年01月31日 ⁄ 综合 ⁄ 共 543字 ⁄ 字号 评论关闭


//调用系统默认打开方式打开某文件
string path = @"F:/mp3/007.rm";
System.Diagnostics.Process.Start( path ); 

用记事本打开TXT文件:
System.Diagnostics.Process.Start("notepad.exe", txtFilNam);

类似的用IE打开TXT文件:
System.Diagnostics.Process.Start("explorer.exe", filename);

如何打开文件夹,并选中指定文件?
在任务管理器或迅雷等软件中,右击某一项目,有个打开文件夹的选项
这时该文件夹被打开了,而且该文件处于被选中的状态
请问C#中该怎么实现?

如下的代码打开窗口并选中记事本程序:
Process proc = new Process();
proc.StartInfo.FileName = "explorer";
proc.StartInfo.Arguments = @"/select,C:/WINDOWS/system32/notepad.exe";
proc.Start();

也可以简单一些:
System.Diagnostics.Process.Start("explorer",@"/select," + filename); 

抱歉!评论已关闭.