How to modify a message by using ADO in Visual Basic .NET (314380)
The information in this article applies to:
- Microsoft Exchange Server 2003 Enterprise Edition
- Microsoft Exchange Server 2003 Standard Edition
- Microsoft Exchange 2000 Server
This article was previously published under Q314380 INTRODUCTIONThis 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 topCreate 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.
- 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.
back to the topModify the sample code- 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
- Search for the TODO text string in the code, and then modify the code for your environment.
back to the topRun the program- Press F5 to build and to run the program.
- Verify that the specified properties are modified.
back to the top
Modification Type: | Minor | Last Reviewed: | 11/10/2005 |
---|
Keywords: | kbHOWTOmaster kbhowto KB314380 kbAudDeveloper |
---|
|