Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Open XML doc from MemStream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Looch - 15 Oct 2007 16:17 GMT
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
Jon Skeet [C# MVP] - 15 Oct 2007 16:31 GMT
> I have a memory stream that I saved an XML doc to.
>
[quoted text clipped - 6 lines]
> 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
Nicholas Paldino [.NET/C# MVP] - 15 Oct 2007 16:32 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi All,
>
[quoted text clipped - 10 lines]
>
> Thanks
amdrit - 15 Oct 2007 16:33 GMT
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).

> Hi All,
>
[quoted text clipped - 10 lines]
>
> Thanks
Ignacio Machin ( .NET/ C# MVP ) - 15 Oct 2007 16:42 GMT
Hi,

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

Signature

Ignacio Machin
www.laceupsolutions.com
Mobile & warehouse Solutions.

> Hi All,
>
[quoted text clipped - 10 lines]
>
> Thanks
Christof Nordiek - 15 Oct 2007 16:43 GMT
> Hi All,
>
[quoted text clipped - 8 lines]
> 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
Peter Bromberg [C# MVP] - 15 Oct 2007 16:47 GMT
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

> Hi All,
>
[quoted text clipped - 10 lines]
>
> Thanks
Looch - 15 Oct 2007 18:42 GMT
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.
Jon Skeet [C# MVP] - 15 Oct 2007 19:12 GMT
> 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
[quoted text clipped - 11 lines]
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Looch - 15 Oct 2007 20:37 GMT
Thanks All for the help. I decided to create a temp file to read
from...for now:)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.