How to read the attributes of a Word document in VB.net

Source: Internet
Author: User

Copy codeThe Code is as follows: 'read Custom Attributes
Dim Properties = SourceDoc. CustomDocumentProperties
Dim PropertyType As Type = Properties. GetType

Try
Dim Authorprop = PropertyType. InvokeMember ("Item", Reflection. BindingFlags. Default Or Reflection. BindingFlags. GetProperty, Nothing, Properties, New Object () {"Remarks "})
ResultString = Authorprop. GetType. InvokeMember ("Value", Reflection. BindingFlags. Default Or Reflection. BindingFlags. GetProperty, Nothing, Authorprop, New Object (){})

Catch ex As Exception

End Try
'Write
Dim Authorprop = PropertyType. InvokeMember ("Item", Reflection. BindingFlags. Default Or Reflection. BindingFlags. SetProperty, Nothing, properties, New Object () {"Remarks", ResultString })

Another method:

Copy codeThe Code is as follows: 'Add a new property
SourceDoc. CustomDocumentProperties. Add (Name: = "PropertyName", LinkToContent: = False, Type: = Microsoft. Office. Core. MsoDocProperties. msoPropertyTypeString, Value: = "PropertyValue ")

'Modify attributes
SourceDoc. CustomDocumentProperties ("PropertyName"). Value = PropertyValue

'Get the property value
PropertyValue = SourceDoc. CustomDocumentProperties ("PropertyName"). Value

Copy codeThe Code is as follows: 'read the built-in attributes. Take the remarks as an example.
ResultString = SourceDoc. BuiltInDocumentProperties (Microsoft. Office. Interop. Word. WdBuiltInProperty. wdPropertyComments). value

After reading the write operation, you can right-click the Word document and choose Properties to view the effect. However, when the word document is open, right-click the document and there is no "Custom" or "abstract" Tab.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.