Microsoft KB Archive/256517

= BUG: urn:schemas:mailheader:from Field Is Corrupted When Binding to an ADO Stream =

Article ID: 256517

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.6
 * Collaboration Data Objects for Exchange 2000
 * Microsoft Collaboration Data Objects 2.0

-



This article was previously published under Q256517



SYMPTOMS
When you bind to an ASCII file using an ActiveX Data Objects (ADO) Stream object, the field name urn:schemas:mailheader:from may be corrupted.



CAUSE
By default, the ADO Stream object uses the Unicode character set. Because the data in the newsgroup post (.nws) is ASCII, the field name becomes corrupted due to the mismatched character sets. ADO adds the Unicode byte-order marks to the beginning of any ASCII file, which creates a custom header as shown below.

Standard Header:

urn:schemas:mailheader:from

Modified Header:

urn:schemas:mailheader:from



WORKAROUND
To work around this problem, specify that the stream contains ASCII text before loading the file: Sub main Dim oMsg As New CDO.Message Dim oStream As New ADODB.Stream Dim oField As ADODB.Field

Dim i As Integer Dim sFilepath As String sFilepath = "\\servername\directory\test.nws" 'Note: The line below is the only change to the code in the "More Information" section. oStream.Charset = "us-ascii" oStream.Open oStream.LoadFromFile sFilepath oStream.Flush

oMsg.BodyPart.DataSource.OpenObject oStream, cdoAdoStream 'Print all of the fields. i = 0 For Each oField In oMsg.Fields Debug.Print i & ") " & oField.Name & " = " & oField.Value      i = i + 1    Next    'Query for the "From" Field.    For Each oField In oMsg.Fields     If (oField.Name = "urn:schemas:mailheader:from") Then        Debug.Print oField.Name & " = " & oField.Value     End If    Next End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Use Microsoft Outlook Express to save a newsgroup post to your hard disk. This file should have an .nws extension . In Microsoft Visual Basic, create a new Standard EXE project. Reference the Microsoft ActiveX Data Objects 2.5 Library and the Microsoft CDO for Exchange 2000 Library.  Copy the following code to a Visual Basic module: Sub main Dim oMsg As New CDO.Message Dim oStream As New ADODB.Stream Dim oField As ADODB.Field

Dim i As Integer Dim sFilepath As String sFilepath = "\\servername\directory\test.nws"

oStream.Open oStream.LoadFromFile sFilepath oStream.Flush

oMsg.BodyPart.DataSource.OpenObject oStream, cdoAdoStream 'Print all of the fields. i = 0 For Each oField In oMsg.Fields Debug.Print i & ") " & oField.Name & " = " & oField.Value      i = i + 1    Next    'Query for the field "From".      For Each oField In oMsg.Fields     If (oField.Name = "urn:schemas:mailheader:from") Then        Debug.Print oField.Name & " = " & oField.Value     End If    Next End Sub                     Run the code.</li></ol>

Keywords: kbbug kbnofix KB256517

-

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

© Microsoft Corporation. All rights reserved.