0

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.

enter image description here

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Keifer Bly
  • 47
  • 1
  • 4
  • Please can you include your error message as _text_. – ProgrammingLlama Aug 06 '20 at 23:52
  • It says Argument 1: cannot convert from 'string[]' to 'System.Diagnostics.ProcessStartInfo' Thanks. – Keifer Bly Aug 07 '20 at 01:03
  • Look up the documentation for `Process.Start`. I very much doubt that there's a version that takes a `string[]` or am `IEnumerable`. I know there is a version that takes a `ProcesdStartInfo`. Where did you get the idea to pass in a string array? Start by figuring out what you want to pass (I'm guessing from your code that it's the full path to WinWord). Get that working. Then figure out how to start it. BTW, do you know you can start Word by passing `blahblah.docx`? – Flydog57 Aug 07 '20 at 04:07
  • Thanks. I just pointed it to where Word normally is and that works. – Keifer Bly Aug 07 '20 at 06:46

0 Answers0