Search code examples
c#office-interop

C# Word Interop cannot Add document


I try to add a document from template with Microsoft.Office.Interop.Word, using:

Microsoft.Office.Interop.Word.Aplication wordApp = 
             new Microsoft.Office.Interop.Word.Application();

wordApp.Documents.Add("somedoc.dotx");

But I always get an unhandled COMException, telling me the file might be damaged. I tried doc, docx and dotx and I am sure the file exists, because I check it before. When I open the file in Word, it opens fine.


Solution

  • Turns out, Add() wants a full path:

    wordApp.Documents.Add(Path.GetFullPath("somedoc.docx"));
    

    works fine, with both docx and dotx files.