Question

How can I view the content I write with XMLWriter object to a MemoryStream object?
Note that the MemoryStreamobject isn't a member field of the class and I don't have access to it in the relevant method in which I write to it with XMLWriter.

I thought I will be able to look at the MemoryStream by the XMLWriter object itself, which is linked to the MemoryStream it writes to, but It seems that who wrote XMLWriter didn't think about that option. :\

Thanks

Was it helpful?

Solution

I assume you would like to get string value from your MemoryStream object? Try this:

    memoryStream.Position = 0;
    var sr = new StreamReader(memoryStream);
    var myStr = sr.ReadToEnd();
    Console.WriteLine(myStr);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top