I've created an office:word add-in using visual studio tools for office (VSTO). I've modified the loadehavior of the add-in to '0' to stop its auto load behavior.
My requirement is to start an word document from a c# application and enable the add-in only for this word instance.
Using Word = Microsoft.Office.Interop.Word;
{
Word.Application wordApp;
//Instantiate a word application
wordApp = new Word.Application();
wordApp.visible = true;
// Open a document
wordApp.Documents.Open(ref wordFile, ref Missing.value, ..... etc );
foreach (Word.AddIns addins in wordApp.Application.AddIns)
MessageBox.Show(addins.ToString());
}
for loop throws exception:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.AddIn'
* how to get/store/iterate list of addins/COMaddins *
Regards,
finally I found solution to my problem:
// This will return all the word addins
Microsoft.Office.Core.COMAddIns comAddins = wordApp.COMAddIns;
// Iterate through all the addins
for(Microsoft.Office.Core.COMAddIns addins in wordApp.COMAddIns)
MessageBox.Show(addin.Description);