다음을 통해 공유


Creating Property Definitions

Topic Last Modified: 2006-06-15

To create a property definition

  1. Create an item in one of your application's schema folders. You must place the item in a folder that is in your application folder's schema scope.
  2. Set the item's contentclass Field to the value "urn:content-classes:propertydef". This identifies the item as a property definition.
  3. Set the name of the property by using the name Field for the item. This name is used to refer to the property definition. Note that this name is not the URL for the item. For example, a property definition located at the URL https://server/public/myapplication/schema/property1 may have the name "urn:schemas-myschema-tld:propA". This name is used to refer to the property in applicable item fields, such as the element Field property for a content class definition item.
  4. Set the property's data type by using the type Field.
  5. Define whether the property is multivalued by setting the ismultivalued Field for the item.
  6. Define whether the property is indexed by setting the isindexed Field for the item.
  7. Set the default Field to a default value.
  8. Define whether the property is read-only by setting the isreadonly Field for the item.

Example

VBScript

Example

Dim InfoNT
Set InfoNT = CreateObject("WinNTSystemInfo")
Dim sPath
sPath = "/public/test_folder/schema/"

CreatePropDefs "http://" & InfoNT.ComputerName & sPath

Sub CreatePropDefs( sSchemaFolderUrl )

 '
 ' This example creates the following property definitions:
 '   urn:schemas-domain-tld:submitdate
 '   urn:schemas-domain-tld:cuisine
 '   urn:schemas-domain-tld:title
 '   urn:schemas-domain-tld:ingredients
 '   urn:schemas-domain-tld:instructions
 '   urn:schemas-domain-tld:rating
 ' These properties are used in the urn:schemas-domain-tld:content-classes:recipe
 ' content class.
 '
 ' A URN scheme is used for the namespace: "urn:schemas-domain-tld:"
 '  where "tld" refers to "top-level domain".

 Dim Conn
 set Conn = CreateObject("ADODB.Connection")
 Conn.Provider = "ExOLEDB.DataSource"
 Conn.Open sSchemaFolderUrl

 Dim Rec
 Set Rec = CreateObject("ADODB.Record")

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

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

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

 ' Create the property definition in the schema folder for ingredients
 Rec.Open sSchemaFolderUrl & "ingredients", Conn,adModeReadWrite, adCreateNonCollection
 Set Flds = Rec.Fields
 With Flds
   .Item("DAV:contentclass") = "urn:content-classes:propertydef"
   .Item("urn:schemas-microsoft-com:xml-data#name")  = "urn:schemas-domain-tld:ingredients"
   .Item("urn:schemas-microsoft-com:datatypes#type") = "string"

   ' Note that ismultivalued is set to true for handling multiple ingredients
   .Item("urn:schemas-microsoft-com:exch-data:ismultivalued") = True
   .Item("urn:schemas-microsoft-com:exch-data:isindexed")     = True
   .Item("urn:schemas-microsoft-com:exch-data:isreadonly")    = False
   .Update
 End With
 Rec.Close

 ' Create the property definition in the schema folder for instructions
 Rec.Open sSchemaFolderUrl & "instructions", Conn,adModeReadWrite, adCreateNonCollection
 Set Flds = Rec.Fields
 With Flds
   .Item("DAV:contentclass") = "urn:content-classes:propertydef"
   .Item("urn:schemas-microsoft-com:xml-data#name")  = "urn:schemas-domain-tld:instructions"
   .Item("urn:schemas-microsoft-com:datatypes#type") = "string"

   ' Note that ismultivalued is set to true for handling multiple instructions
   .Item("urn:schemas-microsoft-com:exch-data:ismultivalued") = True
   .Item("urn:schemas-microsoft-com:exch-data:isindexed")     = False
   .Item("urn:schemas-microsoft-com:exch-data:isreadonly")    = False
   .Update
 End With
 Rec.Close

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

 ' Clean up.
 Conn.Close
 Rec.Close

 Set Conn = Nothing
 Set Rec = Nothing

End Sub

C#

Example

// Creates a custom property definition in the application
// schema folder.
// To use the Microsoft ActiveX Data Object Library, a reference to the Microsoft ActiveX
// Data Object Library must be added to the Visual C# project.
private bool DefineCustProperty(string strSchemaFldrURL, string strNamespace,
        string strPropName, string strDataType, string strDefaultVal,
        bool bIsMultiValued, bool bIsIndexed, bool bIsReadOnly)
{
        // Variables.
        ADODB.Connection cnnSchemaFldr;
        ADODB.Record recProp;

        // Initialize the connection.
        cnnSchemaFldr = new ADODB.Connection();

        // Initialize the record object.
        recProp = new ADODB.RecordClass();

        try
        {
                // Set the provider and open the connection.
                cnnSchemaFldr.Provider = "EXOLEDB.DATASOURCE";
                cnnSchemaFldr.Open(strSchemaFldrURL,"" ,"" ,0);

                // Open and configure the record.
                recProp.Open( strSchemaFldrURL + strPropName,
                              cnnSchemaFldr,
                              ADODB.ConnectModeEnum.adModeReadWrite,
                              ADODB.RecordCreateOptionsEnum.adCreateNonCollection
                              | ADODB.RecordCreateOptionsEnum.adCreateOverwrite,
                              ADODB.RecordOpenOptionsEnum.adOpenSource,
                              "", "");

                // Set fields.
                recProp.Fields["DAV:contentclass"].Value = "urn:content-classes:propertydef";
                recProp.Fields["urn:schemas-microsoft-com:xml-data#name"].Value = strNamespace + strPropName;
                recProp.Fields["urn:schemas-microsoft-com:datatypes#type"].Value = strDataType;
                recProp.Fields["urn:schemas-microsoft-com:exch-data:ismultivalued"].Value = bIsMultiValued;
                recProp.Fields["urn:schemas-microsoft-com:exch-data:isindexed"].Value = bIsIndexed;
                recProp.Fields'"urn:schemas-microsoft-com:exch-data:isreadonly"].Value = bIsReadOnly;

                // Set default value.  For simplicity, assuming the default value here is a string.
                recProp.Fields["urn:schemas-microsoft-com:exch-data:defaultvalue"].Value = strDefaultVal;

                // Upadate fields.
                recProp.Fields.Update();

                // Clean up.
                recProp.Close();
                cnnSchemaFldr.Close();

                recProp = null;
                cnnSchemaFldr = null;
        }
        catch(Exception e)
        {
                // Implement custom error handling here.
                MessageBox.Show(e.Message);

                // If the record or connection objects are open, close them.
                if(recProp.State == ADODB.ObjectStateEnum.adStateOpen)
                        recProp.Close();

                if(cnnSchemaFldr.State == 1)
                        cnnSchemaFldr.Close();

                // Clean up.
                recProp = null;
                cnnSchemaFldr = null;
                return false;
        }

        return true;
}

The Microsoft® Exchange Explorer, a tool for managing the Exchange store, may also be used for Creating Property Definitions.