Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

Create the project and set the references

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. In Visual Basic Projects types, click Console Application.

    By default, the file that is named Module1.vb is created.
  4. Add a reference to the Microsoft ActiveX Data Objects 2.5 Library. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, locate the Microsoft ActiveX Data Objects 2.5 Library, and then click Select.
    3. 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.

Modify the sample code

  1. 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 = "http://<ExchServer>/Exchange/<UserAlias>/Inbox/Test.eml"
    
            oCn.Provider = "exoledb.datasource"
            oCn.Open(sItemUrl, "", "", -1)
    
            If oCn.State = 1 Then
                Console.WriteLine("Good Connection")
            Else
                Console.WriteLine("Bad Connection")
                Return
            End If
    
    
            oRc.Open(sItemUrl, oCn, _
             ADODB.ConnectModeEnum.adModeReadWrite, _
             ADODB.RecordCreateOptionsEnum.adFailIfNotExists, _
             ADODB.RecordOpenOptionsEnum.adOpenSource, _
             "", "")
    
            If oRc.State = ADODB.ObjectStateEnum.adStateOpen Then
                Console.WriteLine("Record open is a success.")
            Else
                Console.WriteLine("Record open has failed.")
                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("{0} : {1}", oField.Name, oField.Value)
            Next
    
            ' Modify the Subject property and the Read property by using the Fields object.
            oFields.Item("urn:schemas:mailheader:subject").Value = "Modified Subject"
            oFields.Item("urn:schemas:httpmail:read").Value = True
            oFields.Update()
    
            oRc.Close()
            oCn.Close()
    
            'iMsg = Nothing
            oCn = Nothing
            oRc = Nothing
            oFields = Nothing
            oField = Nothing
        End Sub
    
    End Module
    					
  2. Search for the TODO text string in the code, and then modify the code for your environment.

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


Keywords: KB314380, kbhowto, kbhowtomaster

↑ Back to the top

Article Info
Article ID : 314380
Revision : 5
Created on : 11/29/2007
Published on : 11/29/2007
Exists online : False
Views : 287