Microsoft KB Archive/286755

= How to Create an Index on a Custom Property =

Article ID: 286755

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Collaboration Data Objects for Exchange 2000
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6

-



This article was previously published under Q286755



SUMMARY
This article demonstrates how to use ActiveX Data Objects (ADO) to create a custom property that is indexed.



MORE INFORMATION
This Visual Basic sample demonstrates the following tasks:
 * It sets the property definition urn:schemas-microsoft-com:exch-data:isindexed to TRUE. (Note that this setting alone does not create the index.) The code that follows the comment &quot;Create the property definition in the schema folder for title&quot; indicates how to do this.
 * It defines a content class that includes the custom property. The code below the comment &quot;Create the content class recipe&quot; indicates how to do this.
 * It includes that content class in a folder’s expected content class. This folder is typically the application folder containing the items that hold your data. The code that follows the comment &quot;Setting the expected content class for the application folder (myapp)&quot; indicates how to do this.
 * It uses CREATE INDEX to create indexes on all properties that are defined in the folder’s expected content class. (This function indexes all items in a folder rather than individually.) The code that follows the comment &quot;Create indexes on all properties that are defined in the folder’s expected content class&quot; indicates how to do this.

To run this sample code, follow these steps:  Create a folder named Myapp in the default public folder subtree, and a subfolder of Myapp named Schema. Reference the Active DS Type Library and the Microsoft ActiveX Data Objects 2.5 Library.  Copy the following code to a Visual Basic module: Const adModeReadWrite = 3 Const adFailIfNotExists = -1 Const adCreateNonCollection = 0

Private Sub Main Dim Conn Dim Info Dim InfoNT Dim sFolderURL Dim sSchemaFolderURL

Set Info = CreateObject(&quot;ADSystemInfo&quot;) Set InfoNT = CreateObject(&quot;WinNTSystemInfo&quot;)

' Path of Virtual Root. sVrootURL = &quot;http://&quot; & InfoNT.ComputerName & &quot;.&quot; & Info.DomainDNSName & &quot;/public&quot;

' Path to the application folder. sFolderURL = sVrootURL & &quot;/myapp&quot;

' Path to the schema folder. sSchemaFolderURL = sVrootURL & &quot;/myapp/schema&quot;

'This example creates an index on custom properties.

' The following property definitions are created: ' urn:schemas-domain-tld:title ' urn:schemas-domain-tld:ingredients ' ' These properties are used in the ' urn:schemas-domain-tld:content-classes:recipe ' content class. ' ' A URN scheme is used for the namespace: &quot;urn:schemas-domain-tld:&quot; ' where &quot;tld&quot; refers to &quot;top-level domain&quot;.

Set Conn = CreateObject(&quot;ADODB.Connection&quot;) Conn.Provider = &quot;ExOLEDB.DataSource&quot; Conn.Open sSchemaFolderURL

Dim Rec Set Rec = CreateObject(&quot;ADODB.Record&quot;)

' Create the property definition in the schema folder for title. ' This property will be the indexed property; note that ' urn:schemas-microsoft-com:exch-data:isindexed is set to True. Rec.Open sSchemaFolderURL & &quot;/title&quot;, Conn, adModeReadWrite, adCreateNonCollection Set Flds = Rec.Fields With Flds .Item(&quot;DAV:contentclass&quot;) = &quot;urn:content-classes:propertydef&quot; .Item(&quot;urn:schemas-microsoft-com:xml-data#name&quot;) = &quot;urn:schemas-domain-tld:title&quot; .Item(&quot;urn:schemas-microsoft-com:datatypes#type&quot;) = &quot;string&quot; .Item(&quot;urn:schemas-microsoft-com:exch-data:ismultivalued&quot;) = False .Item(&quot;urn:schemas-microsoft-com:exch-data:isindexed&quot;) = True .Item(&quot;urn:schemas-microsoft-com:exch-data:isreadonly&quot;) = False .Update End With Rec.Close

' Create the property definition in the schema folder for ingredients. Rec.Open sSchemaFolderURL & &quot;/ingredients&quot;, Conn, adModeReadWrite, adCreateNonCollection Set Flds = Rec.Fields With Flds .Item(&quot;DAV:contentclass&quot;) = &quot;urn:content-classes:propertydef&quot; .Item(&quot;urn:schemas-microsoft-com:xml-data#name&quot;) = &quot;urn:schemas-domain-tld:ingredients&quot; .Item(&quot;urn:schemas-microsoft-com:datatypes#type&quot;) = &quot;string&quot; .Item(&quot;urn:schemas-microsoft-com:exch-data:ismultivalued&quot;) = True .Item(&quot;urn:schemas-microsoft-com:exch-data:isindexed&quot;) = False .Item(&quot;urn:schemas-microsoft-com:exch-data:isreadonly&quot;) = False .Update End With Rec.Close

' Create the content class recipe. Rec.Open sSchemaFolderURL & &quot;/ccdef-recipe&quot;, Conn, adModeReadWrite, adCreateNonCollection

Set Flds = Rec.Fields With Flds ' Name the content class. .Item(&quot;urn:schemas-microsoft-com:xml-data#name&quot;).Value = _ &quot;urn:schemas-domain-tld:content-classes:recipe&quot; ' The content class of the definition item. .Item(&quot;DAV:contentclass&quot;) = &quot;urn:content-classes:contentclassdef&quot; ' The content classes it extends (inherits from). .Item(&quot;urn:schemas-microsoft-com:xml-data#extends&quot;).Value = _ Array(&quot;urn:content-classes:item&quot;) ' The additional properties that belong to this content class. .Item(&quot;urn:schemas-microsoft-com:xml-data#element&quot;).Value = _ Array(&quot;urn:schemas-domain-tld:title&quot;, &quot;urn:schemas-domain-tld:ingredients&quot;) .Update End With

Rec.Close Conn.Close

' Set properties on the application folder. Conn.Open sFolderURL

Rec.Open sFolderURL, Conn, adModeReadWrite

Set Flds = Rec.Fields With Flds .Item(&quot;urn:schemas-microsoft-com:exch-data:schema-collection-ref&quot;) = sSchemaFolderURL 'Setting the expected content class for the application folder (myapp) .Item(&quot;urn:schemas-microsoft-com:exch-data:expected-content-class&quot;) = _ Array(&quot;urn:schemas-domain-tld:content-classes:recipe&quot;) .Update End With Rec.Close

' Set baseschema property on the schema folder. Rec.Open sSchemaFolderURL, Conn, adModeReadWrite

Set Flds = Rec.Fields With Flds .Item(&quot;urn:schemas-microsoft-com:exch-data:baseschema&quot;) = Array(CStr(&quot;/public/non_ipm_subtree/Schema&quot;)) .Update End With Rec.Close

' Create indexes on all properties that are defined in the folder’s expected content class. Conn.Execute &quot;CREATE INDEX * ON &quot;&quot;&quot; & sFolderURL & &quot;&quot;&quot; (*)&quot;

' Create an item in the application folder using these custom properties. Rec.Open sFolderURL & &quot;/test1.txt&quot;, Conn, adModeReadWrite, adCreateNonCollection Or adCreateOverwrite

Set Flds = Rec.Fields With Flds .Item(&quot;urn:schemas-domain-tld:title&quot;).Value = &quot;Title of Recipe&quot; .Item(&quot;urn:schemas-domain-tld:ingredients&quot;).Value = Array(&quot;ingredient1&quot;, &quot;ingredient2&quot;, &quot;ingredient3&quot;) .Item(&quot;DAV:contentclass&quot;) = &quot;urn:schemas-domain-tld:content-classes:recipe&quot; .Update End With

Rec.Close Conn.Close

End Sub 

Additional query words: Property Index

Keywords: kbinfo kbprogramming KB286755

-

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

© Microsoft Corporation. All rights reserved.