How to turn a string into an ADO.Stream?
- From: "John Mark Howell" <jmarkhowell@xxxxxxxxxxx>
- Date: Mon, 26 Sep 2005 10:11:53 -0500
I'm stuck. I can turn a string into an ADO.Stream by writing it out to a
file and then using the ADO.Stream.LoadFromFile but I would like to not have
to write it out to a file. Anybody can help with either the VB.Net code or
the C# code. Any help at all would be greatly appreciated!!!
Here is both the C# and the VB.Net code. The VB.Net code does not get an
error but does not load the CDO.Message object with anything. I can dump
the stream (so.ToString()) and see that the buffer does indeed have
something, but the CDO.Message.DataSource does not seem to recognize that it
is at the beginning of the stream. So, other than a ".Position = 0", if
someone can help be find a way to get the stream to be reset to an unread
state would be a great help.
The C# code gets an error on the "WriteText" line saying that "Operation is
not allowed when the object is open". However, when you comment out the
".Open" command you get "Operation is not allowed when the object is
closed".
' VB.Net Code:
Public Sub TestWithString(ByVal buf As String)
' now build the ADODB.Stream object
Dim so As New ADODB.Stream
so.Mode = ConnectModeEnum.adModeReadWrite
so.Type = StreamTypeEnum.adTypeText
so.Open()
so.WriteText(buf, StreamWriteEnum.adWriteLine)
' reset the position in the stream
so.Position = 0
' now build the CDO message
Dim msg As New CDO.Message
msg.DataSource.OpenObject(so, "_Stream")
Console.WriteLine(msg.TextBody)
End Sub
// C# Code:
public void TestUsingStringOnly(String msgText)
{
Console.WriteLine(">> TestUsingStringOnly is beginning.\n");
ADODB.StreamClass stream = new ADODB.StreamClass();
stream.Open(Missing.Value, ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
stream.Type = ADODB.StreamTypeEnum.adTypeText;
stream.Mode = ADODB.ConnectModeEnum.adModeReadWrite;
stream.WriteText(msgText, ADODB.StreamWriteEnum.adWriteLine);
stream.Position = 0;
CDO.Message msg = new CDO.MessageClass();
msg.DataSource.OpenObject(stream, "_Stream");
// test the message
Console.Write("TextBody: ");
Console.WriteLine(msg.TextBody);
Console.WriteLine("<< TestUsingStringOnly is finished.\n\n");
}
.
- Follow-Ups:
- Re: How to turn a string into an ADO.Stream?
- From: Mark J. McGinty
- Re: How to turn a string into an ADO.Stream?
- Prev by Date: Re: ActualSize returns -1 for Text fields
- Next by Date: Re: ActualSize returns -1 for Text fields
- Previous by thread: how to know wat is the data source name.
- Next by thread: Re: How to turn a string into an ADO.Stream?
- Index(es):
Relevant Pages
|
|