Help with System.IO.Stream

  • Thread starter Thread starter Michael H
  • Start date Start date
M

Michael H

I need to pass my XML string as a stream to a method;

eg.

public SubmitResult ClickToRecord.Submit(
Stream stream,
ConflictResolutionPolicy policy,
out ProgramDetails[] programsInConflict
)



How can/should I pass this XML string via a stream to a method such as
this ??

Thanks,

Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio
 
A stream just contains a sequence of bytes, it has nothing to do with XML.
XML is simply the format of those bytes. Either you pass a stream to the
method or you must pass some class that interprets the XML such as an
XmlTextReader or XmlDocument.
 
You would use Encoding.GetBytes() to convert your XML string to a byte array
then pass the byte array into the stream by using Stream.Write().

HTH

DalePres
MCAD, MCDBA, MCSE
 
A stream just contains a sequence of bytes, it has nothing to do with XML.
XML is simply the format of those bytes. Either you pass a stream to the
method or you must pass some class that interprets the XML such as an
XmlTextReader or XmlDocument.

I appreciate your input Peter, though I know this, but what I'm doing
now causes a CLR runtime error.

"Application has generated an exception that could not be handled."

"Process id=0xea0 (3744), Thread id=0x564 (1380)."

It could always be from the method call to Submit(....), this MCE2k5
isn't spitting out any details in the console window. I'll check that
next.

// xml is a string filled with xml.

byte[] byteArr;

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

byteArr = encoding.GetBytes(xml);

Microsoft.Windows.MediaCenter.ProgramDetails [] details;

System.IO.Stream sr = new System.IO.MemoryStream(byteArr);

ClickToRecord.Submit( sr,

Microsoft.Windows.MediaCenter.ClickToRecord.ConflictResolutionPolicy.AllowConflict,
out details);



I was just having a brainfart earlier on how to start with a stream,
move the data to a byte array, then use the byte array to instantiate
a Stream object for passing to my Submit() method. Too much work is
frying my brain, eh?

Have a good weekend,

Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio
 
Back
Top