SoftwareSamples #2 – Run an application with C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("notepad.exe");
}
}
}

Here is what you should do if you want to open a file in Notepad:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RunNotepad
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("notepad.exe", "C:/path/filename.txt");
}
}
}

Replace C:\path\filename.txt with the path and name of the file. Also, you would usually do backward-slash in Windows instead of forward slash. However, if you use backward-slash the application will run up a bunch of errors.

You can change the application that is launched. If you had SeaSurf installed at C:\Users\yourusername\Desktop\SeaSurfForWindows.exe, for example, you could launch that.

 

Advertisements

Go on, you know you want to! Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s