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);
- }
Comments