Create XML file using folder path..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhagyap
    New Member
    • Nov 2011
    • 14

    Create XML file using folder path..

    Hi..

    I have checkedlistbox in Form1 which gives me path of an folder with the checked items now using the checked items(path) i want to create XML File and populate it into TreeView in Form2..

    Can anyone please help me??
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Are you unsure as to how to save an XmlDocument to a file, or how to build the XmlDocument object in the first place? I'm a bit confused by what you're asking, can you please clarify your request? Please include any relevant data and anything you've already tried.

    Thanks!

    Comment

    • bhagyap
      New Member
      • Nov 2011
      • 14

      #3
      Save CheckedItems and Bulid XML

      System.IO.Direc toryInfo di = new System.IO.Direc toryInfo("E:\\T esting");
      System.IO.FileS ystemInfo[] files = di.GetDirectori es();
      checkedListBox1 .Items.AddRange (files);


      Options opt = new Options();
      XmlDocument document = new XmlDocument();
      XmlElement rootElement = document.Create Element("Items" );
      foreach (var itemObj in opt.checkedList Box1.CheckedIte ms)
      {
      XmlElement newItem = document.Create Element("Item") ;
      newItem.InnerTe xt =itemObj.ToStri ng();
      rootElement.App endChild(newIte m);
      }
      document.Append Child(rootEleme nt);
      document.Save(" test.xml");

      I am using above code to populate checkedlistbox and then create XML but i am unable to fetch checked items..

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        So the problem is that you can save them, but you're unable to retrieve them?

        If this is the case, an XmlDocument object has a LoadXml method that you can use. You supply the source XML as a string (which you would read from the file you saved) and it loads the XML into the XmlDocument object that calls it. Make sure you call it from within a try/catch block as if there are any exceptions, you'll want to be able to report the errors.

        Now you'll have an XmlDocument object that's the same as the one you wrote. Just process it to get the nodes containing the names of the items you want checked, then find them in your listbox and check them.

        Comment

        Working...