Visual Studio,WinForms 问题 CSharp
Visual Studio, WinForms issue CSharp
我卡在了一点。
我有一个按钮可以搜索并执行路径/.exe
但问题是我公司有1%的人没有安装这个软件,如果他们点击它,他们会得到错误找不到特定的文件夹文件。
如何编辑代码 IF(错误)然后继续并显示 MSG。 “您没有安装此应用程序”?
代码:
{
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\xxx\xxxxx\xxxx.vbs");
}
错误:在屏幕截图中
here
你应该使用异常处理:
try
{
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\xxx\xxxxx\xxxx.vbs");
}
catch (System.ComponentModel.Win32Exception ex)
{
MessageBox.Show("You don't have this application installed");
}
如果文件存在,你应该为此添加一个条件,执行它否则做其他事情,像这样:
using System.IO;
using System.Diagnostics;
var path = "Path to your File";
if(File.Exists(path))
{
Process.Start(path);
}
else
{
//do sth else
}
我卡在了一点。
我有一个按钮可以搜索并执行路径/.exe
但问题是我公司有1%的人没有安装这个软件,如果他们点击它,他们会得到错误找不到特定的文件夹文件。
如何编辑代码 IF(错误)然后继续并显示 MSG。 “您没有安装此应用程序”?
代码:
{
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\xxx\xxxxx\xxxx.vbs");
}
错误:在屏幕截图中 here
你应该使用异常处理:
try
{
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\xxx\xxxxx\xxxx.vbs");
}
catch (System.ComponentModel.Win32Exception ex)
{
MessageBox.Show("You don't have this application installed");
}
如果文件存在,你应该为此添加一个条件,执行它否则做其他事情,像这样:
using System.IO;
using System.Diagnostics;
var path = "Path to your File";
if(File.Exists(path))
{
Process.Start(path);
}
else
{
//do sth else
}