直接打开指定的文件
System.Diagnostics.Process.Start(v_OpenFilePath);
直接打开目录
string v_OpenFolderPath = @"目录路径"; System.Diagnostics.Process.Start("explorer.exe", v_OpenFolderPath);
在WinForm/C#中打开一个文件,主要是用到进程的知识。
下面是一些实例,可以模仿着去实现。
1. 打开文件
private void btOpenFile_Click(object sender, EventArgs e)
{
//定义一个ProcessStartInfo实例
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
//设置启动进程的初始目录
info.WorkingDirectory = Application.StartupPath;
//设置启动进程的应用程序或文档名
info.FileName = @"test.txt";
//设置启动进程的参数
info.Arguments = "";
//启动由包含进程启动信息的进程资源
try
{
System.Diagnostics.Process.Start(info);
}
catch (System.ComponentModel.Win32Exception we)
{
MessageBox.Show(this, we.Message)