Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("E:\\Testing");
System.IO.FileSystemInfo[] files = di.GetDirectories();
checkedListBox1.Items.AddRange(files);

Options opt = new Options();
XmlDocument document = new XmlDocument();
XmlElement rootElement = document.CreateElement("Items");
foreach (var itemObj in opt.checkedListBox1.CheckedItems)
{
XmlElement newItem = document.CreateElement("Item");
newItem.InnerText =itemObj.ToString();
rootElement.AppendChild(newItem);
}
document.AppendChild(rootElement);
document.Save("test.xml");



hi, error at code?! " Options opt = new Options();"

C#
Options opt = new Options();



error! Is not defined

error at code :
Error 1 The type or namespace name 'Options' could not be found (are you missing a using directive or an assembly reference?)

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
 
namespace WindowsFormsApplication18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("E:\\Testing");
            System.IO.FileSystemInfo[] files = di.GetDirectories();
            checkedListBox1.Items.AddRange(files);
 

            Options opt = new Options();
            XmlDocument document = new XmlDocument();
            XmlElement rootElement = document.CreateElement("Items");
            foreach (var itemObj in opt.checkedListBox1.CheckedItems)
            {
                XmlElement newItem = document.CreateElement("Item");
                newItem.InnerText = itemObj.ToString();
                rootElement.AppendChild(newItem);
            }
            document.AppendChild(rootElement);
            document.Save("test.xml");
        }
    }
}
Posted
Updated 2-Jul-12 7:58am
v4
Comments
ZurdoDev 2-Jul-12 12:52pm    
Would you like to share the error please?
Tim Groven 2-Jul-12 12:53pm    
What is the error you are getting?
AshishChaudha 2-Jul-12 12:54pm    
what error?
Kiran Susarla 2-Jul-12 12:54pm    
can you please share the error details?
[no name] 2-Jul-12 12:55pm    
You would need to add a reference to the assembly where Options is defined and then add a using statement for it.

1 solution

I think you are copied code from internet and try to compile it.

http://bytes.com/topic/c-sharp/answers/923938-create-xml-file-using-folder-path[^]

able to find same code from that link.

that is not a complete solution, it is small part of a windows form project. you can't copy past and run it.

There will be compile errors since you don't have defined Options in your project. It may be a windows form in that given link.
 
Share this answer
 
v2
Comments
DamithSL 2-Jul-12 13:26pm    
why this is down voted! better if you can leave a comment
BillW33 2-Jul-12 15:33pm    
Looks like a good answer, +5 from me.
Sergey Alexandrovich Kryukov 2-Jul-12 16:18pm    
Of course this is an idiotic vote of 1. I just voted 5, but this vote of 1 remains.
This is not a worst case; from time to time, someone comes and vote "1" for some ten of my posts in a row, maybe even without reading them, it looks like. Some members here are apparently crazy... I mean... accentuated; :-) just take it easy...
--SA
lewax00 2-Jul-12 13:35pm    
Looks like you're right...in which case the question makes little sense. +5

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