Setting the Schema Collection Reference for a Folder
Topic Last Modified: 2006-06-12
The following example demonstrates how to set the schema-collection-ref Field for a folder. This property indicates the Uniform Resource Identifier (URI) of the first folder in which to search for schema definition items. If this property is not set, the default location is the non_ipm_subtree/Schema folder in the public store or private store where the folder resides.
Note
To access the global schema of an application or a public store, use The ##SCHEMAURI## Macro.
Example
VBScript
Example
<Job id="SetupFolderschema">
<reference object="adodb.record"/>
<script language="vbscript">
Option Explicit
Dim Info
Dim InfoNT
Dim oRec
Dim oRec2
Dim Conn
Dim sVrootURL
Dim sFolderURL
Dim sSchemaFolderURL
Set Info = CreateObject("ADSystemInfo")
Set InfoNT = CreateObject("WinNTSystemInfo")
Set Conn = CreateObject("ADODB.Connection")
sVrootURL = "http://" & InfoNT.ComputerName & "/public/"
sFolderURL = "appfolder/"
sSchemaFolderURL = "schema/"
Conn.Provider = "ExOLEDb.DataSource"
Conn.Open sVrootURL
Set oRec = CreateObject("ADODB.Record")
oRec.Open sVrootURL & sFolderURL, Conn, adModeReadWrite, adCreateCollection
oRec.Fields("DAV:contentclass") = "urn:content-classes:folder"
'''''''''''''''''''''''''''''''''''''''''''''
' Here the schema-collection-ref URL is set.'
' '
'''''''''''''''''''''''''''''''''''''''''''''
oRec.Fields("urn:schemas-microsoft-com:exch-data:schema-collection-ref") = _
sVrootURL & sFolderURL & sSchemaFolderURL
oRec.Fields.Update
Set oRec2 = CreateObject("ADODB.Record")
oRec2.Open sVrootURL & sFolderURL & sSchemaFolderURL, Conn, adModeReadWrite, adCreateCollection
oRec2.Fields("DAV:contentclass") = "urn:content-classes:folder"
oRec2.Fields("urn:schemas-microsoft-com:exch-data:baseschema").Value = Array( sVrootURL & "non_ipm_subtree/Schema")
oRec2.Fields.Update
wscript.echo oRec.Fields("urn:schemas-microsoft-com:exch-data:schema-collection-ref")
</script>
</Job>
C++
Example
#import <msado15.dll> no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace
#include <iostream.h>
void setSchemaColRef(bstr_t sFolderUrl) {
_RecordPtr Rec(__uuidof(Record));
_ConnectionPtr Conn(__uuidof(Connection));
Conn->Provider = "ExOLEDB.DataSource";
try {
Conn->Open(sFolderUrl, bstr_t(), bstr_t(), -1);
}
catch(_com_error e) {
cout << "Error opening connection." << endl;
//..
throw e;
}
try {
Rec->Open(sFolderUrl,
variant_t((IDispatch*)Conn,true),
adModeReadWrite,
adCreateCollection,
adOpenSource,
bstr_t(),
bstr_t());
}
catch(_com_error e) {
cout << "Error opening item" << endl;
//..
}
FieldsPtr Flds;
Flds = Rec->Fields;
FieldPtr Fld;
Fld = Flds->Item["urn:schemas-microsoft-com:exch-data:schema-collection-ref"];
Fld->Value = bstr_t("http://server.example.com/vroot/path/to/collection/");
try {
Flds->Update();
}
catch(_com_error e) {
cout << "update failed" << endl;
cout << e.Description() << endl;
}
}
C#
Example
// Sets the schema collection reference for a application 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 SetFolderSCR(string strFldrURL, string strAppSchemaURL)
{
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.adCreateCollection,
ADODB.RecordOpenOptionsEnum.adOpenSource,
"", "");
// Set the urn:schemas-microsoft-com:exch-data:schema-collection-ref field.
recAppFldr.Fields["urn:schemas-microsoft-com:exch-data:schema-collection-ref"].Value = strAppSchemaURL;
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;
}