This project has moved and is read-only. For the latest updates, please go here.

CustomeDocumentProperties

Aug 11, 2011 at 2:23 PM

Hi All,

Please let me know how we can use customdocument properties.

I am facing issue while converting customdocumentproperties into DocumentProperties object.

My code is like this:

Me.m_Properties = CType(docObj.CustomDocumentProperties, NetOffice.OfficeApi.DocumentProperties)

I am getting this exception: DocumentProperties class not found in LateBindingApi.

Thanks

Aug 11, 2011 at 3:33 PM

i have no idea which office product you use? is that word?
do you have a small code snippet for me?

Aug 11, 2011 at 5:02 PM

Yes, I am using word.

Public

 Class DocPropertiesForm

 

Private m_Properties As New NetOffice.OfficeApi.DocumentProperties 'DWNET/1115-Sunny

 

'Private m_xmlOptions As XmlDocument 'DWNET/661 - Nagesh

 

Public Overloads Function ShowDialog(ByVal docObj As Document) As DialogResult 'DWNET/1115-Sunny '

 

Try

 

'DWNET/661 - Nagesh - Code is moved to new class WordTemplates

 

 

Me.m_Properties = CType(docObj.CustomDocumentProperties, DocumentProperties) 'DWNET/1115-Sunny

Last line is throwing exception which is like this:  DocumentProperties class not found in LateBindingApi.

If possible please give me an example to access word document custom properties.

Thanks in Advance

 

Aug 11, 2011 at 5:27 PM

are you sure you have a reference to office and a imports statement?
the follwing testcode works fine for me.

Imports LateBindingApi.Core
Imports Word = NetOffice.WordApi
Imports Office = NetOffice.OfficeApi
Imports NetOffice.WordApi.Enums

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        ' initialize api
        LateBindingApi.Core.Factory.Initialize()

        ' start word and turn off msg boxes
        Dim wordApplication As New Word.Application
        wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone

        ' add a new document
        Dim newDocument As Word.Document
        newDocument = wordApplication.Documents.Add()

        Dim m_Properties As New NetOffice.OfficeApi.DocumentProperties
        m_Properties = CType(newDocument.CustomDocumentProperties, Office.DocumentProperties)
        m_Properties = newDocument.CustomDocumentProperties ' works also

    End Sub

End Class
 


Aug 11, 2011 at 7:07 PM

Thanks for your answer but still I am getting the same exception. I am using 2.0 framework library. I have refernce to office and imports statement.

Imports

System.Xml

'>>DWNET/1115-Sunny

Imports

System.Windows.Forms

Imports

NetOffice.WordApi

Imports

NetOffice.OfficeApi

Imports

Word = NetOffice.WordApi.Enums

Imports

NetOffice.OfficeApi.Enums

Imports

LateBindingApi.Core

'<<DWNET/1115-Sunny

Namespace

TemplateEditor.Client

 

Public Class DocPropertiesForm

 

Private m_Properties As New NetOffice.OfficeApi.DocumentProperties 'DWNET/1115-Sunny

 

'Private m_xmlOptions As XmlDocument 'DWNET/661 - Nagesh

 

Public Overloads Function ShowDialog(ByVal docObj As NetOffice.WordApi.Document) As DialogResult 'DWNET/1115-Sunny '

 

Try

 

'DWNET/661 - Nagesh - Code is moved to new class WordTemplates

 

Me.m_Properties = CType(docObj.CustomDocumentProperties, NetOffice.OfficeApi.DocumentProperties) 'DWNET/1115-Sunny

ChkBoxPanel.Controls.Clear()

ChkBoxPanel.SuspendLayout()

 

Dim xnProperties As XmlNodeList = Template.GetDocProperties() 'DWNET/661 - Nagesh

 

If Not xnProperties Is Nothing Then

 

For Each xnProperty As System.Xml.XmlNode In xnProperties 'DWNET/1115-Sunny : XMLNode is ambigious,Netoffice.Wordapi, System.Xml

 

If (CanAdd(docObj, xnProperty)) Then

AddCheckBox(docObj, xnProperty)

 

End If

 

Next

 

End If

ChkBoxPanel.ResumeLayout(

True)

 

Return Me.ShowDialog()

 

Catch ex As Exception

Trace.WriteLine(ex)

 

End Try

 

End Function

Aug 11, 2011 at 8:42 PM

Thanks for your help...it worked...:)