Microsoft KB Archive/294789

= How To Create a Custom Content Class With Date and Integer Custom Properties =

Article ID: 294789

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft ActiveX Data Objects 2.5

-



This article was previously published under Q294789



SUMMARY
This article contains a Microsoft Visual Basic code sample that demonstrates how to use ActiveX Data Objects (ADO) to create an item of a custom content class with string, date, and integer custom properties.



MORE INFORMATION
To run this sample code, follow these steps:  In Visual Basic, create a new Standard EXE project.  Add a button to the default form and paste the following code in the button's Click event: Const URI_CONTENT_CLASS = &quot;DAV:contentclass&quot; Const URI_EXPECTED_CONTENT_CLASS = _ &quot;urn:schemas-microsoft-com:exch-data:expected-content-class&quot; Const URI_SCHEMA_COLLECTION_REF = _ &quot;urn:schemas-microsoft-com:exch-data:schema-collection-ref&quot; Const URI_ISHIDDEN = &quot;DAV:ishidden&quot; Const URI_NAME = &quot;urn:schemas-microsoft-com:xml-data#name&quot; Const URI_TYPE = &quot;urn:schemas-microsoft-com:datatypes#type&quot; Const URI_ISMULTIVALUED = _ &quot;urn:schemas-microsoft-com:exch-data:ismultivalued&quot; Const URI_ISINDEXED = &quot;urn:schemas-microsoft-com:exch-data:isindexed&quot; Const URI_ISREADONLY = &quot;urn:schemas-microsoft-com:exch-data:isreadonly&quot; Const URI_ELEMENT = &quot;urn:schemas-microsoft-com:xml-data#element&quot; Const URI_CC_FOLDER = &quot;urn:content-classes:folder&quot; Const URI_CC_CONTENTCLASSDEF = &quot;urn:content-classes:contentclassdef&quot; Const URI_CC_PROPERTYDEF = &quot;urn:content-classes:propertydef&quot;

Dim cn As ADODB.Connection Dim rec As ADODB.Record Dim strRoot As String Dim strAppURL As String Dim strSchemaURL As String

' TO DO: Replace ServerName with your Exchange 2000 server name. strRoot = &quot;http://ServerName/public/&quot; strAppURL = strRoot & &quot;AppFolder/&quot; strSchemaURL = strAppURL & &quot;Schema/&quot;

Set cn = CreateObject(&quot;ADODB.Connection&quot;) cn.Provider = &quot;EXOLEDB.DATASOURCE&quot; cn.Open strRoot

' Create the Application folder. Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strAppURL, cn, adModeReadWrite, _ (adCreateCollection Or adCreateOverwrite) .Fields(URI_CONTENT_CLASS) = URI_CC_FOLDER .Fields(URI_SCHEMA_COLLECTION_REF) = &quot;./Schema/&quot; .Fields(URI_EXPECTED_CONTENT_CLASS) = Array( _       &quot;urn:schemas-domain-com:content-classes:test&quot;) .Fields.Update .Close End With Set rec = Nothing

' Create the Schema folder. Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strSchemaURL, cn, adModeReadWrite, _ (adCreateCollection Or adCreateOverwrite) .Fields(URI_CONTENT_CLASS) = URI_CC_FOLDER .Fields(URI_ISHIDDEN) = True .Fields.Update .Close End With Set rec = Nothing

' Fill the schema folder with content class definitions. 'Create a property definition. Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strSchemaURL & &quot;propdefName.reg&quot;, cn, adModeReadWrite, _ adCreateNonCollection .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF .Fields(URI_NAME) = &quot;urn:schemas-domain-com:Name&quot; .Fields(URI_TYPE) = &quot;string&quot; .Fields(URI_ISMULTIVALUED) = False .Fields(URI_ISINDEXED) = False .Fields(URI_ISREADONLY) = False .Fields.Update .Close End With Set rec = Nothing

Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strSchemaURL & &quot;propdefDate.reg&quot;, cn, adModeReadWrite, _ adCreateNonCollection .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF .Fields(URI_NAME) = &quot;urn:schemas-domain-com:Date&quot; .Fields(URI_TYPE) = &quot;dateTime&quot; .Fields(URI_ISMULTIVALUED) = False .Fields(URI_ISINDEXED) = False .Fields(URI_ISREADONLY) = False .Fields.Update .Close End With Set rec = Nothing

Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strSchemaURL & &quot;propdefNumber.reg&quot;, cn, adModeReadWrite, _ adCreateNonCollection .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF .Fields(URI_NAME) = &quot;urn:schemas-domain-com:Num&quot; .Fields(URI_TYPE) = &quot;int&quot; .Fields(URI_ISMULTIVALUED) = False .Fields(URI_ISINDEXED) = False .Fields(URI_ISREADONLY) = False .Fields.Update .Close End With Set rec = Nothing

'Create a content class definition. Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open strSchemaURL & &quot;ccdef.reg&quot;, cn, adModeReadWrite, _ adCreateNonCollection .Fields(URI_CONTENT_CLASS) = URI_CC_CONTENTCLASSDEF .Fields(URI_NAME).Value = _ &quot;urn:schemas-domain-com:content-classes:test&quot;

.Fields(URI_ELEMENT).Value = Array( _       &quot;urn:schemas-domain-com:Name&quot;, _        &quot;urn:schemas-domain-com:Date&quot;, _        &quot;urn:schemas-domain-com:Num&quot;) .Fields.Update .Close End With Set rec = Nothing

cn.Close Set cn = Nothing

Set cn = CreateObject(&quot;ADODB.Connection&quot;) cn.Provider = &quot;EXOLEDB.DATASOURCE&quot; cn.Open strAppURL

' Create a new record in AppFolder with the content class that you created. Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec Set rec = CreateObject(&quot;ADODB.Record&quot;) With rec .Open &quot;newrec.eml&quot;, cn, adModeReadWrite, adCreateNonCollection .Fields(URI_CONTENT_CLASS) = _ &quot;urn:schemas-domain-com:content-classes:test&quot; .Fields(&quot;urn:schemas-domain-com:Name&quot;).Value = &quot;greeting&quot; .Fields(&quot;urn:schemas-domain-com:Date&quot;).Value = _ CDate(&quot;4/7/2000 12:40:19 AM&quot;) .Fields(&quot;urn:schemas-domain-com:Num&quot;).Value = CLng(&quot;1001&quot;) .Fields.Update .Close End With Set rec = Nothing

cn.Close Set cn = Nothing  In the code, replace &quot;ServerName&quot; with your Exchange 2000 server name. Add a reference to the Microsoft ActiveX Data OBjects 2.5 Library. Run the program and click the button. Note that a public folder named AppFolder has been created. This folder contains a hidden folder named Schema, which contains the content class and property definitions.

 Run the Web Storage System Explorer tool. This tool ships with the Exchange 2000 Software Development Kit (SDK) tools. Verify that Newrec.eml has been created in AppFolder. Newrec.eml contains the following data types and values: </li></ol>

Keywords: kbhowto kbmsg KB294789

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.