How to turn a string into an ADO.Stream?



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");
}


.



Relevant Pages

  • Re: Question about design, defmacro, macrolet, and &environment
    ... "Expects to find the literal string on the stream." ... (defun send (string &optional stream) ... (declaim (inline make-adjustable-string)) ...
    (comp.lang.lisp)
  • Re: How to turn a string into an ADO.Stream?
    ... > someone can help be find a way to get the stream to be reset to an unread ... > Public Sub TestWithString(ByVal buf As String) ... > ' now build the CDO message ... > Dim msg As New CDO.Message ...
    (microsoft.public.data.ado)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReplacerStream
    ... string, do a replace on that string and create a stream again to be ... If those are problems, and you are looking just for a single string, it seems to me that you could just read the stream one character at a time, checking to see if it matches the current character in your search string. ...
    (microsoft.public.dotnet.framework)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)