可以调用cmd来实现
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd";
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.CreateNoWindow = false; cmd.Start();
cmd.StandardInput.WriteLine(@"d:\a.doc"); //这里可以换成从文件对话框取得文件名
cmd.Close();
用默认程序打开文件
private void OpenFiles()
{
string fileName = "";//文件名
//打开文件对话框
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
fileName = ofd.FileName;
try
{
if (fileName != "" && System.IO.File.Exists(fileName))
{
System.Diagnostics.Process.Start(fileName);
}
}
catch (System.Exception e)
{
MessageBox.Show("打开文件失败" + e.Message);
}
}