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 "standardised" 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.Current.Response.OutputStream
//To write to the Console pass in Console.OpenStandardOutput()
public Boolean TransformDataset(System.IO.Stream strmOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(strmOut,System.Text.Encoding.UTF8,640 );
flgSuccess = prvTransformDataset();
strmOutput.Close();
return(flgSuccess);
}
//String argument defines file to create
public Boolean TransformDataset(string strOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(strOut);
flgSuccess = prvTransformDataset();
strmOutput.Close();
return(flgSuccess);
}
//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 TransformDataset()
{
strmLocal = new MemoryStream();
strmLocal.Seek(0,SeekOrigin.Begin);
strmOutput = new StreamWriter(strmLocal,System.Text.Encoding.UTF8,6 40);
try
{
if(prvTransformDataset())
{
strmLocal.Position = 0;
StreamReader strmRdOut = new
StreamReader(strmLocal,System.Text.Encoding.UTF8);
return(strmRdOut.ReadToEnd().ToString());
}
else
{
return("Failed!");
}
}
finally
{
strmOutput.Close();
}
}
Stephen
"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message
news:ed****************@tk2msftngp13.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.writeXML("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.Stream and the
XPathDocument supports load from System.IO.Stream but I can not seem to
get this to work.
Any suggestions?
Cheers
Keith