I have a question regarding launching an external application from an asp.net website. Now I think there are security measures in place to prevent that and I know it's not a good practice, but for an intranet site I'm developing it would be incredibly handy to be able to do that.
So far I've found where I can launch an external app if I'm running my server locally (in debug) then it works fine. When I publish the files out to my webserver it no longer works. I know my filepaths are going to be different I imagine, but how can I check if a local file exists? Or can I?
So here's my code:
//the actual launch button on the page
protected void btnLaunchTnet_Click(object sender, EventArgs e)
{
string tnetpath = "c:\path\tnet.exe";
RunProcess(tnetpath, "");
}
private void RunProcess(string cmd, string arguments)
{
System.Diagnostics.Process p;
p = new System.Diagnostics.Process();
p.StartInfo.FileName = cmd;
if (arguments.Length > 1)
{
p.StartInfo.Arguments = arguments;
}
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.UseShellExecute = false;
p.Start();
}
I also have a quick 'check if this file exists' that I use to disable or enable the button that launches the app
private bool CheckFileExists(string filepath)
{
FileInfo SetupPath = new FileInfo(filepath);
return SetupPath.Exists;
}
I know of a way using ActiveX controls, but then it would work only with Internet Explorer.
Check out this post.