Microsoft KB Archive/314380

= How to modify a message by using ADO in Visual Basic .NET =

Article ID: 314380

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition

-



This article was previously published under Q314380



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
 * Create the project and set the references
 * Modify the sample code
 * Run the program



INTRODUCTION
This article describes how to use the Microsoft ActiveX Data Objects 2.5 Library with the Exchange OLE DB Provider (ExOLEDB) to modify the Subject property and the Read property of a message. You can use Microsoft Visual Basic .NET to do this.

back to the top

Create the project and set the references
 Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. In Visual Basic Projects types, click Console Application.

By default, the file that is named Module1.vb is created. Add a reference to the Microsoft ActiveX Data Objects 2.5 Library. To do this, follow these steps:  On the Project menu, click Add Reference. On the COM tab, locate the Microsoft ActiveX Data Objects 2.5 Library, and then click Select.</li> In the Add References dialog box, click OK to accept your selections.

If you receive a message to generate wrappers for the libraries that you select, click Yes.</li></ol> </li></ol>

back to the top

Modify the sample code
<ol>  In the Code window, replace all the code with the following code: Module Module1

Sub Main Dim oCn As ADODB.Connection = New ADODB.Connection Dim oRc As ADODB.Record = New ADODB.Record

Dim oFields As ADODB.Fields Dim oField As ADODB.Field

' TODO: Replace with your message URL. Dim sItemUrl As 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 Then Console.WriteLine(&quot;Good Connection&quot;) Else Console.WriteLine(&quot;Bad Connection&quot;) Return End If

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

If oRc.State = ADODB.ObjectStateEnum.adStateOpen Then Console.WriteLine(&quot;Record open is a success.&quot;) Else Console.WriteLine(&quot;Record open has failed.&quot;) Return End If

oFields = oRc.Fields

' List the fields. Dim i As Integer For i = 0 To oFields.Count - 1 oField = oFields.Item(i) Console.WriteLine(&quot;{0} : {1}&quot;, oField.Name, oField.Value) Next

' Modify the Subject property and the Read property by using the Fields object. oFields.Item(&quot;urn:schemas:mailheader:subject&quot;).Value = &quot;Modified Subject&quot; oFields.Item(&quot;urn:schemas:httpmail:read&quot;).Value = True oFields.Update

oRc.Close oCn.Close

'iMsg = Nothing oCn = Nothing oRc = Nothing oFields = Nothing oField = Nothing End Sub

End Module </li> Search for the TODO text string in the code, and then modify the code for your environment.</li></ol>

back to the top

Run the program

 * 1) Press F5 to build and to run the program.
 * 2) Verify that the specified properties are modified.

back to the top

Additional query words: Visual Basic VB .NET CDOEX ADO EXOLEDB Modify Message

Keywords: kbhowtomaster kbhowto KB314380

-

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

© Microsoft Corporation. All rights reserved.