Following code of my Microsoft Office WORD VSTO Add-in, was successfully getting the document title before. But now, it's throwing the error shown below:
string sTitle = oActiveDoc.BuiltInDocumentProperties["Title"].Value;
Error:
Cannot apply indexing with [] to an expression of type 'object'
Based on some similar online solutions (such as this and this) to the issue I tried the following code but I'm still getting the exact same error.
Question: What I may be missing here and how can it be resolved?
Ref: Document.BuiltInDocumentProperties gets a Microsoft.Office.Core.DocumentProperties collection
that represents all the built-in document properties for the document.
Following also gives the exact same error:
string sTitle = oActiveDoc.BuiltInDocumentProperties["Title"].Value as string;
or
string sTitle = oActiveDoc.BuiltInDocumentProperties["Title"] as string;
VSTO
projects since2010
, obviously the machines (XP, VISTA, Win10, etc.), the Visual Studio versions (2010,2012,2013,2015,2019) along with Office versions 92003/2007/2010/2016/O365 etc.) have changed, as well. And the same line of code worked on all those versions before. It seems from this post, the above code of line may not always be reliable. – nam