Keith,
Using streams can get a bit interesting
I have a habit of tying myself in knots by creating one level too many of
writers and readers before I factor out all the rubbish again
I've "standardis ed" on the following overloads to methods that return
streams (callers for my earlier Transform dataset example)
Note should probably give thought to using exceptions to flag failure
//Accept a stream to handle web response
//Can be called from ASP.Net using HttpContext.Cur rent.Response.O utputStream
//To write to the Console pass in Console.OpenSta ndardOutput()
public Boolean TransformDatase t(System.IO.Str eam strmOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(st rmOut,System.Te xt.Encoding.UTF 8,640);
flgSuccess = prvTransformDat aset();
strmOutput.Clos e();
return(flgSucce ss);
}
//String argument defines file to create
public Boolean TransformDatase t(string strOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(st rOut);
flgSuccess = prvTransformDat aset();
strmOutput.Clos e();
return(flgSucce ss);
}
//Overload that returns a string
//Uses an in memory stream as a buffer
//Not sure that this is the best way to achieve this
public string TransformDatase t()
{
strmLocal = new MemoryStream();
strmLocal.Seek( 0,SeekOrigin.Be gin);
strmOutput = new StreamWriter(st rmLocal,System. Text.Encoding.U TF8,640);
try
{
if(prvTransform Dataset())
{
strmLocal.Posit ion = 0;
StreamReader strmRdOut = new
StreamReader(st rmLocal,System. Text.Encoding.U TF8);
return(strmRdOu t.ReadToEnd().T oString());
}
else
{
return("Failed! ");
}
}
finally
{
strmOutput.Clos e();
}
}
Stephen
"Keith Chadwick" <kc*******@leew ardsystems.com> wrote in message
news:ed******** ********@tk2msf tngp13.phx.gbl. ..
I have a merged dataset that contains xml read from SQL Server. I need to
place the data into an XPathDocument.
I can do the following:
mydataset.write XML("mydata.xml ")
dim xpdoc as new XPathDocument(" mydata.xml")
Problem is it seem rather redundent to write data currently in memory to
disk in order to be read on the next line. According to the documentation
the writeXML method supports writing to System.IO.Strea m and the
XPathDocument supports load from System.IO.Strea m but I can not seem to
get this to work.
Any suggestions?
Cheers
Keith