|
-
October 2nd, 2008, 03:14 PM
#1
Displaying an Xml file in a Windows form application
Is there a way to display an Xml file in a Windows form application; just like the IE browser does?
-
October 2nd, 2008, 03:24 PM
#2
Re: Displaying an Xml file in a Windows form application
Code:
string s = File.ReadAllText("test.xml");
textbox1.text = s;
-
October 2nd, 2008, 06:48 PM
#3
Re: Displaying an Xml file in a Windows form application
You can also put an IEBrowser control inside the form and load it via the control.
That way you'll be able to expand and collapse the nodes.
-
October 3rd, 2008, 02:38 AM
#4
Re: Displaying an Xml file in a Windows form application
 Originally Posted by Arjay
You can also put an IEBrowser control inside the form and load it via the control.
That way you'll be able to expand and collapse the nodes.
I would like the user to be able to expand and collapse the Xml nodes, so this sounds like a good solution.
But, how can I put an IEbrowser control inside the form?
-
October 3rd, 2008, 03:29 AM
#5
Re: Displaying an Xml file in a Windows form application
Use the WebBrowser Control.
Goto : Add Reference, Under COM tab, choose WebBrowser. (System.Windows.Forms)
You will find this control in the toolbox after adding it.
Now just place it on the form.
MMH.
-
October 3rd, 2008, 08:38 AM
#6
Re: Displaying an Xml file in a Windows form application
Thanks.
Now I have a WebBrowser object on my form.
I tried the following just to see if someting happens, but there was no result.
Code:
StreamReader stream = new StreamReader(fileName);
this.webBrowser1.DocumentStream = stream.BaseStream;
Is this the way to go?
My intention is to display the contents of a DataSet in an Xml format, before the data is actually saved to an Xml file.
-
October 3rd, 2008, 08:48 AM
#7
Re: Displaying an Xml file in a Windows form application
string filename = "C:\\temp\example.xml";
webBrowser1.Url = new Uri(filename);
-
October 3rd, 2008, 09:32 AM
#8
Re: Displaying an Xml file in a Windows form application
 Originally Posted by dannystommen
string filename = "C:\\temp\example.xml";
webBrowser1.Url = new Uri(filename);
It works.
As I understand, using the Url property requires a file. But, is there a way to display the contents of a DataSet in an Xml format on the WebBrowser before the data is actually saved to an Xml file.
-
October 3rd, 2008, 10:33 AM
#9
Re: Displaying an Xml file in a Windows form application
 Originally Posted by Holly_vi
It works.
As I understand, using the Url property requires a file. But, is there a way to display the contents of a DataSet in an Xml format on the WebBrowser before the data is actually saved to an Xml file.
It does not neccesarally need a file, you could also fill in an url, try
webBrowser1.Url = new Uri("http://www.codeguru.com");
To get a dataset into Xml you should use the XmlDataDocument type instead of XmlDocument.
The next codesnippet with a normal XmlDocument works
Code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Properties.config");
webBrowser1.Url = new Uri(xmlDoc.BaseURI);
I never worked with datasets but it should be something like the next
Code:
XmlDataDocument xmlDataDoc = new XmlDataDocument(yourDataSet);
webBrowser1.Url = new Uri(xmlDataDoc.BaseURI);
-
October 10th, 2008, 05:00 AM
#10
Re: Displaying an Xml file in a Windows form application
 Originally Posted by dannystommen
I never worked with datasets but it should be something like the next
Code:
XmlDataDocument xmlDataDoc = new XmlDataDocument(yourDataSet);
webBrowser1.Url = new Uri(xmlDataDoc.BaseURI);
I need to display the contents of my DataSet before it is saved to file, so when I do as you suggest, xmlDataDoc.BaseURI returns null.
Any suggestions?
-
October 10th, 2008, 06:37 AM
#11
Re: Displaying an Xml file in a Windows form application
I looked at it, and xmlDataDoc is indeed empty.
I suggest to save the xmlDataDoc in a temp directory, then open the file with a xmlDocument, and after you did everything you wanted to do, you could delete the file
Code:
XmlDataDocument xmlDataDoc = new XmlDataDocument(dataset);
string fileName = @"C:\temp\data.xml";
xmlDataDoc.Save(fileName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
webBrowser1.Url = new Uri(xmlDoc.BaseURI);
//do the things you want to do
//at the end, delete the file
FileInfo fi = new FileInfo(fileName);
fi.Delete();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|