sorry joe, send you the wrong file,
Here you go:
MyObject myObject = new MyObject(5);
System.IO.StreamWriter sw = new StreamWriter("test.xml");
XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
serializer.Serialize(sw, myObject);
// access the stream
Stream stream = sw.BaseStream;
sw.Close();
You could also use a MemoryStream object if that works for you...
Regards,
Bennie Haelen
Bennie Haelen
"Joe Rizla" <te**@morphium.co.uk> wrote in message
news:WI*********************@wards.force9.net...
Thanks very much for this.
But am I mistaken or isn't this an example of Serialization to a file path
("test.xml"), and not to stream?
"Bennie Haelen" <Be***********@jda.com> wrote in message
news:Oh****************@tk2msftngp13.phx.gbl... Here you go,
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
MyObject myObject = new MyObject(5);
FileStream fs = new FileStream("test.xml",
FileMode.OpenOrCreate); XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
serializer.Serialize(fs, myObject);
fs.Close();
}
}
[Serializable]
public class MyObject
{
public MyObject() {}
public MyObject(int state)
{
myState = state;
}
public int MyState
{
get
{
return myState;
}
set
{
myState = value;
}
}
private int myState;
}
"Joe Rizla" <te**@morphium.co.uk> wrote in message
news:OT********************@stones.force9.net... Is there any example code I can find which shows how to Serialize an
object to System.IO.Stream.
The reason why is because I want the pass the stream on: The Stream is
then XSLT Transformed by passing the stream to create an XPathDocument
object.
Thanks
rizlaroller