Share via


Specifying Expected Content Classes for Folders

Topic Last Modified: 2006-06-12

Each folder item has a list of content class names in its expected-content-class Field. These names refer to the names of content class definition items that reside in the folder's schema scope. When you set this property for folders, you are providing schema-aware applications with a list of content class names for the items within the folder. For example, the Exchange store Structured Query Language (SQL) query processor uses this list of names, along with definition items in the folder's schema scope, to determine which properties it should return when a client issues The SELECT * Statement.

The list of content class names identified in this property does not restrict the possible values that you can set for an item's DAV:contentclass property; it merely indicates to schema-aware applications what class of content to expect in the folder.

The following examples demonstrates how to set the expected-content-class Field on a folder.

Example

VBScript

Note

The following example uses a file URL with the Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme. Using The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.

Example

' Update the application folder to specify the schema scope

Const adModeReadWrite   = 3
Const adFailIfNotExists = -1

Dim sURL
sURL = "file://./backofficestorage/example.com/pubtreeroot"

Dim Rec
Dim Conn
Dim Flds

Set Conn = CreateObject("ADODB.Connection")
Set Rec  = CreateObject("ADODB.Record")

Conn.Provider = "ExOLEDB.DataSource"
Conn.Open sURL
Rec.Open  sURL & "/myapp/myappfolder/", Conn, adModeReadWrite

Set Flds = Rec.Fields
With Flds

  ' Specify which content classes are expected for this folder.
  ' Here, a custom content class is specified along with the standard folder
  ' content class urn:content-classes:folder.

   .Item("urn:schemas-microsoft-com:exch-data:expected-content-class").Value = _
       Array("urn:schemas-domain-tld:content-classes:mycontentclass", "urn:content-classes:folder")
   .Update
End With

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

C#

Example

// Sets the expected content classes for a 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 SetExpectedCC(string strFldrURL, Object[] expectedCCList)
{
        ADODB.Connection cnnFldr;
        ADODB.Record recAppFldr;

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

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

        try
        {
                // Open the folder connection.
                cnnFldr = new ADODB.ConnectionClass();
                cnnFldr.Provider = "EXOLEDB.DATASOURCE";
                cnnFldr.Open(strFldrURL,"" ,"" ,0);

                // Open the folder record.
                recAppFldr.Open(strFldrURL,
                                cnnFldr,
                                ADODB.ConnectModeEnum.adModeReadWrite,
                                ADODB.RecordCreateOptionsEnum.adOpenIfExists
                                | ADODB.RecordCreateOptionsEnum.adCreateCollection,
                                ADODB.RecordOpenOptionsEnum.adOpenSource,
                                "", "");

                // Set the urn:schemas-microsoft-com:exch-data:expected-content-class field, where expectedCCList is
                // an array of content class names.
                recAppFldr.Fields["urn:schemas-microsoft-com:exch-data:expected-content-class"].Value = expectedCCList;

                recAppFldr.Fields.Update();

                // Clean up.
                recAppFldr.Close();
                cnnFldr.Close();

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

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

                // Clean up.
                cnnFldr = null;
                recAppFldr = null;

                return false;
        }

        return true;
}