Setting the Base Schema Path for a Schema Folder
Topic Last Modified: 2006-06-12
The following example demonstrates how to set the baseschema Field for a schema folder. This property indicates the Uniform Resource Identifiers (URIs) of folders that contain additional schema definition items. The order in which these folder URIs appear in the property is the order in which these folders are searched.
If you define your own schema definition items and place them in your own set of schema folders, make sure that one of your schema folders has the baseschema Field set to the non_ipm_subtree/Schema folder for that store. If not, the global schema definitions will not be in the schema scope.
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 OR adCreateOverWrite
oRec.Fields("DAV:contentclass") = "urn:content-classes:folder"
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"
'''''''''''''''''''''''''''''''''''''''''''''
' Here the baseschema array of URLs is set. '
' '
'''''''''''''''''''''''''''''''''''''''''''''
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 setBaseSchemaForFolder(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;
}
wchar_t* url1 = L"https://server/public/test_folder2";
wchar_t* url2 = L"https://server/public/test_folder3";
wchar_t* url3 = L"https://server/public/non_ipm_subtree/Schema";
VARIANT vVal;
VariantInit(&vVal);
vVal.vt = VT_ARRAY | VT_VARIANT;
SAFEARRAY* psa = NULL;
psa = SafeArrayCreateVector(VT_VARIANT, 0, 3);
if(psa == NULL) {
// handle error here.
}
VARIANT* pVal;
HRESULT hr = S_OK;
hr = SafeArrayAccessData(psa, (void**)&pVal);
if(FAILED(hr)) {
// handle error
}
VariantInit(&(pVal[0]));
pVal[0].vt = VT_BSTR;
pVal[0].bstrVal = SysAllocString(url1);
VariantInit(&(pVal[1]));
pVal[1].vt = VT_BSTR;
pVal[1].bstrVal = SysAllocString(url2);
VariantInit(&(pVal[2]));
pVal[2].vt = VT_BSTR;
pVal[2].bstrVal = SysAllocString(url3);
SafeArrayUnaccessData(psa);
vVal.parray = psa;
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:baseschema"];
Fld->Value = vVal;
SafeArrayDestroy(psa);
VariantClear(&vVal);
psa = NULL;
try {
Flds->Update();
}
catch(_com_error e) {
cout << "update failed" << endl;
cout << e.Description() << endl;
}
// Now, read the props back and print the values...
variant_t vBaseSchema;
vBaseSchema = Flds->Item["urn:schemas-microsoft-com:exch-data:baseschema"]->Value;
if( ! (vBaseSchema.vt == (VT_ARRAY | VT_VARIANT))) {
cout << "Unexpected..." << endl;
// handle error
}
hr = SafeArrayAccessData(vBaseSchema.parray, (void**)&pVal);
if(FAILED(hr)) {
cout << "access data failed!!" << endl;
}
cout << "Set the baseschema property for the folder at \r\n " << sFolderUrl;
cout << " \r\nto the following URLS: " << endl;
cout << bstr_t(pVal[0].bstrVal) << endl;
cout << bstr_t(pVal[1].bstrVal) << endl;
cout << bstr_t(pVal[2].bstrVal) << endl;
SafeArrayUnaccessData(vBaseSchema.parray);
}
C#
Example
// Sets the base schema path for a 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 SetFldrBaseSchema(string strFldrURL, Object[] baseSchemaList)
{
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:baseschema field, where baseSchemaList is
// an array of folder URIs that contain schema definition items. For example, the
// array might contain "https://www.fourthcoffee.com/public/##SchemaURI##/microsoft/ExchangeV1/".
recAppFldr.Fields["urn:schemas-microsoft-com:exch-data:baseschema"].Value = baseSchemaList;
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;
}