Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all
i want to write xml file in wpf using c#. and save it in mydocuments folder.
i am new to wpf is it similar how we write in windows.

plz explain with a simple example.

thanks
VK
Posted
Comments
Pete O'Hanlon 1-Jul-11 8:40am    
Do you want to know how to do it in XLINQ or "classic" XML mode in .NET? The example really depends on which you'll be comfortable with.

see this links.....
Link1[^]
Link2[^]
 
Share this answer
 
Comments
RaviRanjanKr 1-Jul-11 9:38am    
Nice Link, My 5 :)
parmar_punit 2-Jul-11 1:35am    
Thanks
C#
XDocument doc = XDocument.Load(filename);
...
... blah blah
...
filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), filename);
doc.Save(filename);
 
Share this answer
 
In addition to above answer take a look at given article to know how to work with XML files in WPF to read and write
Use XML Files with WPF[^]
 
Share this answer
 
How on Earth using XML can be related to WPF? You certainly have a problem with separation of concerns.

You can work on several different levels. Here is the short overview:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlReader and System.Xml.XmlWriter; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


Besides, you many want not to use XML manually at all but use serialization of Data Contract instead. I strongly recommend using Data Contract.

See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answer where I advocate using this powerful and non-intrusive approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900