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
TRY FOR FREE
Download Data Sync Studio
Tag Cloud
Data Sync
SharePoint
Active Directory
Exchange
Dynamic Columns
RSS
CRM
Security
Migration
Csv
Xml
SQL Server
SQL Admin
2-Way
Ouvvi
ODBC
Oracle
Document Library
Azure
OleDB
Integration
Run Tool
QuickBooks
SQL Agent
MOSS BDC
Solutions
Recent Blog Posts
