I’ve generated winform which will display a list of files in a folder and checked items generate xml file. Now, I wanted to generate a list of files and files in subfolder which should be listed in checkbox list whatever the files I checked will get generate a xml file with file path(as parent) and file name (child) separated as parent and child node, and un checked files also should generate xml file as separate node. Will u please modify my code below:
 
- using System;  
- using System.Collections.Generic;  
- using System.ComponentModel;  
- using System.Data;  
- using System.Drawing;  
- using System.Linq;  
- using System.Text;  
- using System.Threading.Tasks;  
- using System.Windows.Forms;  
- using System.IO;  
- using System.Xml;  
- namespace GetDetails  
- {  
- public partial class Form1 : Form  
- {  
-   
- public Form1()  
- {  
- InitializeComponent();  
- }  
- private void textBox1_TextChanged(object sender, EventArgs e)  
- {  
-   
-   
-   
-   
-   
-   
- }  
- private void button4_Click(object sender, EventArgs e)  
- {  
-   
- FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();  
-   
- folderBrowserDlg.ShowNewFolderButton = true;  
-   
- DialogResult dlgResult = folderBrowserDlg.ShowDialog();  
- if (dlgResult.Equals(DialogResult.OK))  
- {  
-   
- textBox1.Text = folderBrowserDlg.SelectedPath;  
-   
- Environment.SpecialFolder rootFolder = folderBrowserDlg.RootFolder;  
- }  
- }  
- private void button1_Click(object sender, EventArgs e)  
- {  
- FolderBrowserDialog fbd = new FolderBrowserDialog();  
- if (fbd.ShowDialog() == DialogResult.OK)  
- {  
- if (!textBox1.Text.Equals(String.Empty))  
- {  
- if (System.IO.Directory.GetFiles(textBox1.Text).Length > 0)  
- {  
- foreach (string file in System.IO.Directory.GetFiles(textBox1.Text))  
- {  
-   
- checkedListBox1.Items.Add(Path.GetFileName(file));  
- }  
- }  
- else  
- {  
- checkedListBox1.Items.Add(String.Format("No files Found at location: { 0}", textBox1.Text));  
- }  
- }  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-  
-   
- }  
- }  
- private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)  
- {  
- }  
- private void button2_Click(object sender, EventArgs e)  
- {  
- string str = " ";  
- int i;  
- for (i = 0; i < checkedListBox1.Items.Count; i++)  
- {  
- if (checkedListBox1.GetItemChecked(i))  
- {  
- str = (string)checkedListBox1.Items[i];  
- MessageBox.Show(str);  
-   
- }  
- }  
-   
- XmlTextWriter xwriter = new XmlTextWriter("GetDetails.xml", Encoding.Unicode);  
- xwriter.WriteStartDocument();  
- xwriter.WriteStartElement("XMLFILE");  
- xwriter.WriteStartElement("file");  
- xwriter.WriteString(textBox1.Text);  
- xwriter.WriteEndElement();  
- foreach (var item in checkedListBox1.CheckedItems)  
- {  
- xwriter.WriteStartElement("IncludedItems");  
- xwriter.WriteString(item.ToString());  
- xwriter.WriteEndElement();  
- }  
- xwriter.WriteEndElement();  
- xwriter.WriteEndDocument();  
- xwriter.Close();  
- }  
- private void button3_Click(object sender, EventArgs e)  
- {  
- this.Close();  
- }  
- private void Form1_Load(object sender, EventArgs e)  
- {  
- }  
- private void button5_Click(object sender, EventArgs e)  
- {  
- this.Close();  
- }  
- }  
- }