Re: Accessing the Thesaurus in Word 2003 Programmitically in C#



Hi =?Utf-8?B?QmxpbmRDb2Rlcg==?=,

I hope sombody can answe this question...... I've been bangin my head tryin
gto fdind som eosort of sample application that is directly re ferenceing hte
com librbrary for access to the Office 2003 thesaurus results when looking up
a word pregrammicially in a C# application. This SHOULD be simple and as my
Com interopability skills are LOW and I can SEE the results in the VIsual
Studio Debugger as a System.Object returned with Dimestion s (This system.
Object has the Sysnonyms lksited for a word I lookup in the thesaurus.
However, When I call the method: " doc1.Words[1].SynonymInfo.MeaningList" in
C# Code the returned object is System.object I believe HOW CAN I GET THESE
VAULES IN A STRING ARRAY? Do I hafta Cast to somthing from whithin the CVom
oBjects Librbay to get the strings? Can I enumerate the results from System
Object? or need I convert from SYstem.object to System.Object[] ? Sombody
help me.

If you read the Help carefully, you'll see that that data type of the returned
array is a VARIANT. Since the .NET Framework doesn't support this data type, it
converts it to System.Object. This means you have to cast the returned object to
an array. Here's an example

wd.SynonymInfo synInfo = wdDoc.Words[1].SynonymInfo;
object meanings = synInfo.MeaningList;
Array meaningList = (Array) meanings;
MessageBox.Show(String.Format("The term '{0}' has {1} meanings.", testTerm,
meaningList.Length.ToString()));
string allMeanings = "";
foreach (string meaning in meaningList)
{
allMeanings += meaning + "\n";
}
MessageBox.Show(allMeanings);

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

.