Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q294789

↑ Back to the top


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.

↑ Back to the top


More information

To run this sample code, follow these steps:
  1. In Visual Basic, create a new Standard EXE project.
  2. Add a button to the default form and paste the following code in the button's Click event:
    Const URI_CONTENT_CLASS = "DAV:contentclass"
    Const URI_EXPECTED_CONTENT_CLASS = _
        "urn:schemas-microsoft-com:exch-data:expected-content-class"
    Const URI_SCHEMA_COLLECTION_REF = _
        "urn:schemas-microsoft-com:exch-data:schema-collection-ref"
    Const URI_ISHIDDEN = "DAV:ishidden"
    Const URI_NAME = "urn:schemas-microsoft-com:xml-data#name"
    Const URI_TYPE = "urn:schemas-microsoft-com:datatypes#type"
    Const URI_ISMULTIVALUED = _
        "urn:schemas-microsoft-com:exch-data:ismultivalued"
    Const URI_ISINDEXED = "urn:schemas-microsoft-com:exch-data:isindexed"
    Const URI_ISREADONLY = "urn:schemas-microsoft-com:exch-data:isreadonly"
    Const URI_ELEMENT = "urn:schemas-microsoft-com:xml-data#element"
    Const URI_CC_FOLDER = "urn:content-classes:folder"
    Const URI_CC_CONTENTCLASSDEF = "urn:content-classes:contentclassdef"
    Const URI_CC_PROPERTYDEF = "urn:content-classes:propertydef"
    
    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 = "http://ServerName/public/"
    strAppURL = strRoot & "AppFolder/"
    strSchemaURL = strAppURL & "Schema/"
    
    Set cn = CreateObject("ADODB.Connection")
    cn.Provider = "EXOLEDB.DATASOURCE"
    cn.Open strRoot
    
    ' Create the Application folder.
    Set rec = CreateObject("ADODB.Record")
    With rec
        .Open strAppURL, cn, adModeReadWrite, _
            (adCreateCollection Or adCreateOverwrite)
        .Fields(URI_CONTENT_CLASS) = URI_CC_FOLDER
        .Fields(URI_SCHEMA_COLLECTION_REF) = "./Schema/"
        .Fields(URI_EXPECTED_CONTENT_CLASS) = Array( _
            "urn:schemas-domain-com:content-classes:test")
        .Fields.Update
        .Close
    End With
    Set rec = Nothing
    
    ' Create the Schema folder.
    Set rec = CreateObject("ADODB.Record")
    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("ADODB.Record")
    With rec
        .Open strSchemaURL & "propdefName.reg", cn, adModeReadWrite, _
            adCreateNonCollection
        .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF
        .Fields(URI_NAME) = "urn:schemas-domain-com:Name"
        .Fields(URI_TYPE) = "string"
        .Fields(URI_ISMULTIVALUED) = False
        .Fields(URI_ISINDEXED) = False
        .Fields(URI_ISREADONLY) = False
        .Fields.Update
        .Close
    End With
    Set rec = Nothing
    
    Set rec = CreateObject("ADODB.Record")
    With rec
        .Open strSchemaURL & "propdefDate.reg", cn, adModeReadWrite, _
            adCreateNonCollection
        .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF
        .Fields(URI_NAME) = "urn:schemas-domain-com:Date"
        .Fields(URI_TYPE) = "dateTime"
        .Fields(URI_ISMULTIVALUED) = False
        .Fields(URI_ISINDEXED) = False
        .Fields(URI_ISREADONLY) = False
        .Fields.Update
        .Close
    End With
    Set rec = Nothing
    
    Set rec = CreateObject("ADODB.Record")
    With rec
        .Open strSchemaURL & "propdefNumber.reg", cn, adModeReadWrite, _
            adCreateNonCollection
        .Fields(URI_CONTENT_CLASS) = URI_CC_PROPERTYDEF
        .Fields(URI_NAME) = "urn:schemas-domain-com:Num"
        .Fields(URI_TYPE) = "int"
        .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("ADODB.Record")
    With rec
        .Open strSchemaURL & "ccdef.reg", cn, adModeReadWrite, _
            adCreateNonCollection
        .Fields(URI_CONTENT_CLASS) = URI_CC_CONTENTCLASSDEF
        .Fields(URI_NAME).Value = _
            "urn:schemas-domain-com:content-classes:test"
    
        .Fields(URI_ELEMENT).Value = Array( _
            "urn:schemas-domain-com:Name", _
            "urn:schemas-domain-com:Date", _
            "urn:schemas-domain-com:Num")
        .Fields.Update
        .Close
    End With
    Set rec = Nothing
    
    cn.Close
    Set cn = Nothing
    
    Set cn = CreateObject("ADODB.Connection")
    cn.Provider = "EXOLEDB.DATASOURCE"
    cn.Open strAppURL
    
    ' Create a new record in AppFolder with the content class that you created. 
    Set rec = CreateObject("ADODB.Record") With rec
    Set rec = CreateObject("ADODB.Record")
    With rec
        .Open "newrec.eml", cn, adModeReadWrite, adCreateNonCollection
        .Fields(URI_CONTENT_CLASS) = _
            "urn:schemas-domain-com:content-classes:test"
        .Fields("urn:schemas-domain-com:Name").Value = "greeting"
        .Fields("urn:schemas-domain-com:Date").Value = _
            CDate("4/7/2000 12:40:19 AM")
        .Fields("urn:schemas-domain-com:Num").Value = CLng("1001")
        .Fields.Update
        .Close
    End With
    Set rec = Nothing
    
    cn.Close
    Set cn = Nothing
    					
  3. In the code, replace "ServerName" with your Exchange 2000 server name.
  4. Add a reference to the Microsoft ActiveX Data OBjects 2.5 Library.
  5. 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.

  6. Run the Web Storage System Explorer tool. This tool ships with the Exchange 2000 Software Development Kit (SDK) tools.
  7. Verify that Newrec.eml has been created in AppFolder. Newrec.eml contains the following data types and values:
    Collapse this tableExpand this table
    PropertyDataTypeValue
    urn:schemas-domain-com:DatedateTime.tz2000-04-07T00:40:19.000Z
    urn:schemas-domain-com:NameStringgreeting
    urn:schemas-domain-com:Numint1001

↑ Back to the top


Keywords: KB294789, kbmsg, kbhowto

↑ Back to the top

Article Info
Article ID : 294789
Revision : 7
Created on : 2/22/2007
Published on : 2/22/2007
Exists online : False
Views : 315