Open XML doc from MemStream

L

Looch

Hi All,

I have a memory stream that I saved an XML doc to.

I can open an XML file in I.E. using:

System.Diagnostics.Process.Start("C:\\MyXML.xml");

My question is what is the syntax for:

System.Diagnostics.Process.Start(the file I just saved to the
MemoryStream);?

Thanks
 
J

Jon Skeet [C# MVP]

I have a memory stream that I saved an XML doc to.

I can open an XML file in I.E. using:

System.Diagnostics.Process.Start("C:\\MyXML.xml");

My question is what is the syntax for:

System.Diagnostics.Process.Start(the file I just saved to the
MemoryStream);?

There may be ways of doing it entirely in memory with interop, but
it's likely to be much simpler to just write the data out to a
temporary file if you need a separate process to see it.

Jon
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

I don't see a memory stream here, as you are specifying a filename when
calling the Start method (maybe you saved it to a file from a memory
stream).

When you call Start, you are specifying a program to run. The OS will
also take filenames and run the programs associated with them. In this
case, an XML file is associated with internet explorer, which causes IE to
be run with that filename as the first argument. This causes the browser to
open and load the file.
 
A

amdrit

Does it need to be in IE?

Have you considered putting a webbrowser control on one of your own forms
and then writing your memory stream directly to the document object?

Another thing to try is to expose your result as an asp page and change the
header information to that of an xml file.
System.Diagnostics.Process.Start(http://myserver/xmlResults?ID=01001001).
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Just save it to a temp file and use that same line to load it.
 
C

Christof Nordiek

Looch said:
Hi All,

I have a memory stream that I saved an XML doc to.

I can open an XML file in I.E. using:

System.Diagnostics.Process.Start("C:\\MyXML.xml");

My question is what is the syntax for:

System.Diagnostics.Process.Start(the file I just saved to the
MemoryStream);?
You want to start an IE showing content from your own process?

You should look for IE and automation. Maybe this shows you a way. Under the
hood, this will be sending the content of the stream between processes.
You also could simply store the Stream to a temporary file and open that.

Or you use the WebBrowserControl. Then you have a simple IE-Window in your
own app.

Christof
 
G

Guest

We may be having some confusion with the meaning of your post. You say you've
saved an XmlDocument to a MemoryStream. Then at the end you are saying "the
file I just saved to the MemoryStream". You didn't save "a file" to the
MemoryStream, you stored an XmlDocument object in it , which is now
represented by a stream of bytes. What exactly is it that you now want to do
with this?
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
L

Looch

Just to give a little more background, and this may be something for
the ASP group but given that its XML I figured it could be handled
strictly in C# -

The code that calls the web service that returns XML string data that
is passed to the XmlDocument.LoadXml() method is all in code behind a
web page.

An input button on the default web page calls the webmethod with
parameters which returns the XML string which is now represented by
the memory stream (thanks Peter) which at this point is residing on
the web server. I'd like to "open" that document on the client PC
either in another instance of a browser (i.e. in IE with the default
markup) or in a blank page (preferred) that I have already added to
the website.

This is the code I'm using so far that renders the XML doc in a text
box on the client with the formatting and indenting preserved:

{
string a = Request.QueryString["ID"];
string b = Request.QueryString["Date"];
grrct.Service receipt = new grrct.Service();
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(receipt.getIndividualReceipt(a, b));
MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 3;
xdoc.WriteTo(writer);
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
TextBox1.Text = ret; //Shows elements and indentation
}

Since this is on a client PC, saving a local temp file is a bit tricky
from what I've read so far.
 
J

Jon Skeet [C# MVP]

Looch said:
Just to give a little more background, and this may be something for
the ASP group but given that its XML I figured it could be handled
strictly in C# -

The code that calls the web service that returns XML string data that
is passed to the XmlDocument.LoadXml() method is all in code behind a
web page.

An input button on the default web page calls the webmethod with
parameters which returns the XML string which is now represented by
the memory stream (thanks Peter) which at this point is residing on
the web server. I'd like to "open" that document on the client PC
either in another instance of a browser (i.e. in IE with the default
markup) or in a blank page (preferred) that I have already added to
the website.

The easiest way of doing *that* is just to make the XML the sole
response of the page, with a target of a new window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top