Windows Phone Developers

Friday, December 5, 2008

How to get the Custom Properties of a Word Document using VSTO

How to get the Custom Properties of a Word Document using .NET (C#)

CustomDocumentProperties returns the entire collection of custom document properties. Use the Microsoft.Office.Core.DocumentProperties.Item(System.Object) property to return a single member of the collection (a Microsoft.Office.Core.DocumentProperties object) by specifying either the name of the property or the collection index (as a number).

private static void WordCustPropertyExample(Word.Application wAP )

{

// Custom Property Extraction For Word Document

Office.DocumentProperties oCusProps = (Office.DocumentProperties)wAP.ActiveDocument.CustomDocumentProperties;

foreach (Office.DocumentProperty oCusProp in oCusProps)

{

// MessageBox.Show( oCusProp.Name);

}

}

To add a custom property to the Word document using VSTO, use the add method as shown below

//Adding a Custom Property for Word Document

oCusProps.Add("CopyEdited By", false, Office.MsoDocProperties.msoPropertyTypeString, "Santa Barbara", false);

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment: