Microsoft KB Archive/310204

= How to modify a message by using Collaboration Data Objects for Exchange 2000 and an ActiveX Data Objects record in Visual C# =

Article ID: 310204

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Visual C# 2005
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Exchange Server 2000 Service Pack 1
 * Collaboration Data Objects for Exchange 2000
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition

-



This article was previously published under Q310204



Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application



IN THIS TASK

 * INTRODUCTION
 * Modify a message by using an ADO record



INTRODUCTION
This article describes how to use the Microsoft Collaboration Data Objects (CDO) for Exchange 2000 Library to modify a message by using an ActiveX Data Objects (ADO) record in Microsoft Visual C#.

back to the top

Modify a message by using an ADO record
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, click New. Under Project Types, click Visual C# Projects.

Note In Visual Studio 2005, click Visual C# under Project Types. Under Templates, double-click Console Application.

By default, Class1.cs is created.

Note In Microsoft Visual Studio 2005, Program.cs is created by default. Add a reference to the Microsoft CDO for Exchange 2000 Library. To do this, follow these steps:  On the Project menu, click Add Reference.</li> In the Add Reference dialog box, click the COM tab, click Microsoft CDO for Exchange 2000 Library, and then click Select.

Note In Visual Studio 2005, you do not have to click Select.</li> Click OK to accept your selections.

If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li> Follow steps 5a through 5c to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.</li>  In the code window, replace all the code with the following code: using System;

namespace Samples {   class Class1 {       static void Main(string[] args) {           try {           ADODB.Connection oCn = new ADODB.Connection; ADODB.Record oRc = new ADODB.Record;

ADODB.Fields oFields; ADODB.Field oField;

// TODO: Replace the URL with your object URL. string sItemUrl = &quot;http://ExchServer/Exchange/UserAlias/Inbox/Test.eml&quot;; oCn.Provider = &quot;exoledb.datasource&quot;; oCn.Open(sItemUrl, &quot;&quot;, &quot;&quot;, -1);

if(oCn.State == 1) {               Console.WriteLine(&quot;Good Connection&quot;); }           else {               Console.WriteLine(&quot;Bad Connection&quot;); }

oRc.Open(sItemUrl, oCn,                ADODB.ConnectModeEnum.adModeReadWrite,                 ADODB.RecordCreateOptionsEnum.adFailIfNotExists,                ADODB.RecordOpenOptionsEnum.adOpenSource,                &quot;&quot;, &quot;&quot;);

oFields = oRc.Fields; string sUrl; oField = oFields[&quot;DAV:href&quot;]; sUrl = oField.Value.ToString;

CDO.Message iMsg = new CDO.Message; iMsg.DataSource.Open(sUrl, oCn,                ADODB.ConnectModeEnum.adModeReadWrite,                ADODB.RecordCreateOptionsEnum.adFailIfNotExists,                ADODB.RecordOpenOptionsEnum.adOpenSource,                &quot;&quot;, &quot;&quot;);

Console.WriteLine(&quot;{0}&quot;, iMsg.From); Console.WriteLine(&quot;{0}&quot;, iMsg.Subject); Console.WriteLine(&quot;{0}&quot;, iMsg.TextBody);

// Modify some properties. iMsg.Subject = &quot;Modified : &quot; + iMsg.Subject; iMsg.Fields[&quot;urn:schemas:httpmail:read&quot;].Value = true; iMsg.Fields.Update; iMsg.DataSource.Save;

oRc.Close; oCn.Close;

iMsg = null; oCn = null; oRc = null; oFields = null; oField = null; }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }                  }        } }

</li> Modify the code accordingly where you see the TODO comment.</li> Press F5 to build and to run the program.</li> Verify that the specified properties were modified.</li></ol>

back to the top

Additional query words: modify message CDOEX ADO

Keywords: kbmsg kbxml kbcode kbhowtomaster KB310204

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.