다음을 통해 공유


Creating Content Class Definitions

Topic Last Modified: 2006-06-15

To create a content-class definition item

  1. Create a non-folder item to hold the content class definition. 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:contentclassdef". This identifies the item as a content class definition.
  3. Set the content class's name using the name Field for the item. This name refers to the content class definition. Note that this name is not the URL for the item. For example, a content class definition located at the URL https://server/public/myapplication/schema/contentclass1 could have the name "urn:schemas-myschema-tld:content-classes:class1". This name refers to the content class in applicable item fields, for example, a folder's expected-content-class or an item's contentclass Field property.
  4. Optionally, you can extend other content classes by setting the extends Field for the item. This property is an array of strings, in which each string is the name of a content class as designated by the class's name Field. When you extend other content class definition items, your class inherits the property definitions set for each of these classes.
  5. You can also specify the names of property definitions to associate with the content class. If this class extends others, you do not need to specify property names for those classes; they are inherited. To specify the names of property definitions, you set the element Field for the item. This property is an array of strings, in which each string is the name of a property definition in the schema scope.

Example

VBScript

Example

Dim Conn
Dim Info
Dim InfoNT
Dim sSchemaFolderURL

Set Info   = CreateObject("ADSystemInfo")
Set InfoNT = CreateObject("WinNTSystemInfo")

sVrootURL        = "http://" & InfoNT.ComputerName & "." & Info.DomainDNSName & "/public"
sSchemaFolderURL = sVrootURL & "/test_folder/schema"

Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ExOLEDB.DataSource"
Conn.Open sVrootURL

CreateCCDef sSchemaFolderURL, Conn


Sub CreateCCDef( sSchemaFolderURL, Conn )

  Const adModeReadWrite       = 3
  Const adFailIfNotExists     = -1
  Const adCreateNonCollection = 0

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

  Rec.Open sSchemaFolderURL & "/ccdef-recipe", Conn, adModeReadWrite, adCreateNonCollection

  Dim Flds
  Set Flds = Rec.Fields

  With Flds

    ' Name the content class.
    .Item("urn:schemas-microsoft-com:xml-data#name").Value = _
     "urn:schemas-domain-tld:content-classes:recipe"

    ' The content class of the definition item.
    .Item("DAV:contentclass") = "urn:content-classes:contentclassdef"

    ' The content classes it extends (inherits from).
    .Item("urn:schemas-microsoft-com:xml-data#extends").Value = _
        Array("urn:content-classes:item", "urn:content-classes:person")

    ' The properties to belong to this content class.
    .Item("urn:schemas-microsoft-com:xml-data#element").Value = _
         Array("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")

    .Update
  End With

  ' Clean up.
  Conn.Close
  Set Conn = Nothing
  Rec.Close
  Set Rec = Nothing

End Sub
</script>
</Job>

C#

Example

// Creates the custom content class definitions 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 CreateCustContentClassDefns(string strSchemaFldrURL, string strCCPrefix,
                                         string strCCName, Object[] ExtendsList,
                                         Object[] CustPropList)
{
        // Variables.
        ADODB.Connection cnnSchemaFldr;
        ADODB.Record recCC;

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

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

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

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

                // Set fields.
                recCC.Fields["DAV:contentclass"].Value = "urn:content-classes:contentclassdef";
                recCC.Fields["urn:schemas-microsoft-com:xml-data#name"].Value = strCCPrefix + strCCName;
                recCC.Fields["urn:schemas-microsoft-com:xml-data#extends"].Value = ExtendsList;
                recCC.Fields["urn:schemas-microsoft-com:xml-data#element"].Value = CustPropList;

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

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

                recCC = 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(recCC.State == ADODB.ObjectStateEnum.adStateOpen)
                        recCC.Close();

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

                // Clean up.
                recCC = null;
                cnnSchemaFldr = null;

                return false;
        }

        return true;
}