Click here to Skip to main content
14,699,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm attempting to get C# to read a word file so I can write some text to another file but keep getting "System.Runtime.InteropServices.COMException: 'Sorry, we couldn’t find your file. Is it possible it was moved, renamed or deleted?" The file is present. Am I missing something?

Thank you very much for your input.

What I have tried:

//read and write to word file
    string docPath = @"C:\Users\benjamin.johnson\Downloads\2020 - 20 - SC 2020 Quarterly Sustainment Release 8.2.docx";
    Application app = new Application();
    Document doc = app.Documents.Open(docPath);

    string allWords = doc.Content.Text;
Updated 28-Apr-20 11:22am
Maciej Los 28-Apr-20 13:29pm
Does Application refer to Word.Application?
Benjaminj007 28-Apr-20 16:22pm
Yes, that refers to the Word application.

Go to the folder where you can see the file and copy the link from its address bar. Paste that into your docPath, along with the file name. That, too, should be copy/pasted (use "rename" to get it - sometimes a hard-to-see typo is the problem).

For your personal interest, compare your original path string with what you get from the above method and see if they're different.
Maciej Los 29-Apr-20 2:04am
1. go to folder containing target file
2. right click on target file
3. select "properties"
4. click "security" tab
5. copy file location and paste in C# (doc path)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900