Reputation: 2661
I would like to save a Word document according to the Word installed version;
In case it is Word 2003 (appropriate version number is 11), with DOC
extension.
In case the Word version is higer than 2003, with DOCX
extension.
The difference is reflected in the second argument sent to the SaveAS
method:
object fileFormat = GraphDocsSettings.Default.WordInstalledVersion > 11.0?
WdSaveFormat.wdFormatXMLDocument : WdSaveFormat.wdFormatDocument;
wordDoc.SaveAs(ref outputFile, fileFormat, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
However, When using Interop.Word 11.0 I get the following error:
Microsoft.Office.Interop.Word.WDSaveFormat does not contain a definition for wdFormatXMLDocument.
Any ideas?
Upvotes: 2
Views: 3017
Reputation: 309
Use the following project's code base to create and save ms word using c#: https://github.com/kauser-cse-buet/NetOfficeUsage
Upvotes: 0
Reputation: 3588
Not sure the API is exactly the same between different word versions.
If I can make a suggestion - use NetOffice( see link) instead of the office interop assemblies.
the API is the same as the Office Interop API, and it will work with all (current) versions of Microsoft Office.
NB - Here is a sample: http://netoffice.codeplex.com/wikipage?title=Word_Example01
You should import the following namespaces to get it to work:
using NetOffice;
using Word = NetOffice.WordApi;
using NetOffice.WordApi.Enums;
using Office = NetOffice.OfficeApi;
Upvotes: 1
Reputation: 156898
That is because you use the wrong version of the interop assemblies. You cannot reference a value which only exists in higher versions of the framework.
You should use a higher interop version, or create two separate projects, one for the older version of the interop assemblies, one for the higher versions.
Upvotes: 0