TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mounika ymr
NA
90
33.7k
how to generate a checkbox list files and files in subfolder
Sep 26 2017 2:35 PM
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
{
//List listfiles = new List();
public
Form1()
{
InitializeComponent();
}
private
void
textBox1_TextChanged(
object
sender, EventArgs e)
{
//string path;
//path = FolderBrowserDialog.Equals("");
//textBox1.Text = FolderBrowserDialog.SelectedPath;
////path = folderBrowserDialog1.SelectedPath;
//// folderBrowserDialog1.ShowDialog(); // NOT SURE ABOUT USING THIS!
//textBox1.Text = path;
}
private
void
button4_Click(
object
sender, EventArgs e)
{
// Create a new instance of FolderBrowserDialog.
FolderBrowserDialog folderBrowserDlg =
new
FolderBrowserDialog();
// A new folder button will display in FolderBrowserDialog.
folderBrowserDlg.ShowNewFolderButton =
true
;
//Show FolderBrowserDialog
DialogResult dlgResult = folderBrowserDlg.ShowDialog();
if
(dlgResult.Equals(DialogResult.OK))
{
//Show selected folder path in textbox1.
textBox1.Text = folderBrowserDlg.SelectedPath;
//Browsing start from root folder.
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))
{
//Add file in ListBox.
checkedListBox1.Items.Add(Path.GetFileName(file));
}
}
else
{
checkedListBox1.Items.Add(String.Format(
"No files Found at location: { 0}"
, textBox1.Text));
}
}
/*
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK)
{
checkedListBox1.Items.Clear();
string[] files = Directory.GetFiles(fbd.SelectedPath);
string[] dirs = Directory.GetDirectories(fbd.SelectedPath);
foreach(string file in files)
{
checkedListBox1.Items.Add(Path.GetFileName(file));
}
foreach (string dir in dirs)
{
checkedListBox1.Items.Add(Path.GetFileName(dir));
}
}*/
}
}
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);
//xwriter.WriteElementString("SelectedItem", checkedListBox1.Items[i].ToString());
}
}
//System.IO.File.WriteAllText("GetDetails.xml", 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();
}
}
}
Reply
Answers (
1
)
Check box allowing export to datagridview
PDF generation using itextsharp