7 December 2009
Accessing Word Document Properties via Office11 Interop Library
To access Word Document Properties with the Office 2003 Interop Libraries for the .NET Framework you need to use reflection to access the collection and read the Name and Value properties of each item in the List.
For example to Return a List of Document Properties might do something like this.
Code Snippet
- public ICollection<DocumentProperty> GetDocumentProperties()
- {
- ICollection<DocumentProperty> returnValue = new List<DocumentProperty>();
- IEnumerable p = (IEnumerable)_Document.CustomDocumentProperties;
- foreach (object f in p)
- {
- Type item = f.GetType();
- try
- {
- returnValue.Add(new DocumentProperty
- {
- Name = GetProperty<string>(item, f, "Name"),
- Value = GetProperty<object>(item, f, "Value")
- });
- }
- catch (TargetInvocationException)
- {
- //Do nothing
- }
- catch (COMException)
- {
- //Do nothing
- }
- }
- return returnValue;
- }
- private T GetProperty<T>(Type t, object o, string name)
- {
- return (T)t.InvokeMember(name,
- BindingFlags.Default |
- BindingFlags.GetProperty,
- null, o,
- null);
- }
Subscribe to this feed
Click here to subscribe
Tag Cloud
Data Sync
FireBird
ODBC
SharePoint
Oracle
Dynamic Columns
Exchange
Active Directory
Security
Ouvvi
Azure
OleDB
CRM
SQL Server
QuickBooks
Xml
Csv
SQL Admin
2-Way
MOSS BDC
Recent Blog Posts
