Struggling to open Office files from a C# application, .NET 6. Note this works just fine using .NET framework.
The official MS nuget package Microsoft.Office.Interop.Word
appears to support only up to Office 2016. Adding the Microsoft Word 16.0 Object Library COM reference appears to not add support either.
using Microsoft.Office.Interop.Word;
private void button2_Click(object sender, EventArgs e)
{
var ap = new Microsoft.Office.Interop.Word.Application();
Document document = ap.Documents.Open(@"C:\Users\name\Desktop\test.docx");
ap.Visible = true;
}
When clicking this button, the following exception is thrown:
System.IO.FileNotFoundException: 'Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.'
Is there really no support for the current version of 365?
I have verified I have Microsoft.Office.Interop.Word
in C:\Windows\assembly\GAC_MSIL.
When searching for COM references, a search for object
only brings up Microsoft Office 16.0 Object Library
as the remotely suitable search result.
This is not the reference you need.
Instead, search for, Microsoft Word 16.0 Object Library
, substituting word
for each office application you need to interact with.