Deleting Objects Using CDOEX and ADO
Deleting Objects Using CDOEX and ADO
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Visual C++
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 The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.
// Delete an Object Using the Record by Giving the Local Path of the Object // Modify the code where you see TODO and make sure the objects or properties exist. #include <activeds.h> #include <stdio.h> #include <conio.h> #import <msado15.dll> no_namespace rename("EOF","adoEOF") #import <cdoex.dll> no_namespace struct StartOle { StartOle() { CoInitialize(NULL); } ~StartOle() { CoUninitialize(); } } _inst_StartOle; void dump_com_error(_com_error &e) { printf("Oops - hit an error!\n"); printf("\tCode = %08lx\n", e.Error()); printf("\tCode meaning = %s\n", e.ErrorMessage()); _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); printf("\tSource = %s\n", (LPCTSTR) bstrSource); printf("\tDescription = %s\n", (LPCTSTR) bstrDescription); } void DeleteObjects(_bstr_t strDomainName, _bstr_t strLocalPathOfObject); HRESULT GetDomainName(BSTR * bstrDomainName); void main(void) { _bstr_t strDomainName; _bstr_t strLocalPathOfObject; _bstr_t strUser; HRESULT hr = S_OK; BSTR bstrDomainDNSName; // Get your Domain Name. hr = GetDomainName(&bstrDomainDNSName); strDomainName = (_bstr_t)bstrDomainDNSName; // TODO strUser = "user1"; // Sample 1: Delete a folder from "MBX". // Specify the path of the folder to be deleted. // TODO strLocalPathOfObject = "MBX/" + strUser + "/Deleted Items/TestFolder"; DeleteObjects(strDomainName, strLocalPathOfObject); // Sample 2: Delete the file "Hello.txt" from the public folder. // Specify the path of the folder to be deleted. // TODO strLocalPathOfObject = "Public Folders/TestFolder/Hello.txt"; DeleteObjects(strDomainName, strLocalPathOfObject); // Sample 3: Delete a folder from "Public Folders". // Specify the path of the folder to be deleted. // TODO strLocalPathOfObject = "Public Folders/TestFolder"; DeleteObjects(strDomainName, strLocalPathOfObject); } // Delete Object Using Record void DeleteObjects(_bstr_t strDomainName, _bstr_t strLocalPathOfObject) { _ConnectionPtr conn(__uuidof(Connection)); _RecordPtr Rec(__uuidof(Record)); _bstr_t strObjectUrl; HRESULT hr = S_OK; try { // Specify the URL to the item to be deleted. strObjectUrl = "file://./backofficestorage/" + strDomainName + "/" + strLocalPathOfObject; // Open the connection. conn->Provider = "Exoledb.DataSource"; hr = conn->Open(strObjectUrl,"","",0); hr = Rec->Open((_variant_t)strObjectUrl,conn->ConnectionString, adModeReadWrite, adFailIfNotExists, adOpenSource, bstr_t(), bstr_t()); // Delete the object. Rec->DeleteRecord(strObjectUrl, false); // Close the connection. Rec->Close(); conn->Close(); // Clean up. Rec = NULL; conn = NULL; printf("Good Job\n"); } catch(_com_error &e) { dump_com_error(e); } } // GetDomainName // Params: [out] BSTR * bstrDomainName // Output: HRESULT // Purpose: Retrieve the Domain DNS name. HRESULT GetDomainName(BSTR * bstrDomainName) { HRESULT hr = S_OK; IADsADSystemInfo *pADsys; hr = CoCreateInstance(CLSID_ADSystemInfo, NULL, CLSCTX_INPROC_SERVER, IID_IADsADSystemInfo, (void**)&pADsys); hr = pADsys->get_DomainDNSName(bstrDomainName); if (pADsys) pADsys->Release(); return hr; }
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.