I am coding an app in C# Visual Studio 2019, where the app will launch Microsoft Word for the user. However, I am struggling to have the app search for word. I know word installs in different locations based on 64 or 32 bit Windows, the exact version of word etc. So I am handling this by attempting to seach Program files for winword.exe then launch it if found. If it can't find it it launches notepad.
string rootDirectory = System.IO.DriveInfo.GetDrives()[0].RootDirectory.FullName;
string [] files = System.IO.Directory.GetFiles(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"WINWORD.EXE", System.IO.SearchOption.AllDirectories);
Process.Start(files);
}
catch (Exception e)
{
Console.WriteLine("I could not find word, so launching notepad.");
Process.Start("C:\\WINDOWS\\system32\\notepad.exe");
It is using string files to search for word and then process.start(stringname) launches word when found, but it returns this error. Any thoughts would be appreciated, thanks very much.