473,419 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Create XML file using folder path..

14
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??
Nov 17 '11 #1

✓ answered by GaryTexmo

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.

3 7090
GaryTexmo
1,501 Expert 1GB
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!
Nov 17 '11 #2
bhagyap
14
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");

I am using above code to populate checkedlistbox and then create XML but i am unable to fetch checked items..
Nov 18 '11 #3
GaryTexmo
1,501 Expert 1GB
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.
Nov 18 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Keith Smith | last post by:
When I create a setup file (MSI) for my app, I get the following error when I try to run the MSI file... The folder path '.' contains an invalid character Does anyone know a solution to this? ...
1
by: Chung | last post by:
Hi, I am developing an asp.net application. I have create some class method and I would like to get the folder path of that class method. I cannot use this.Mappath("") to get the path because...
2
by: Harshdeep Mehta | last post by:
Hi all gurus, Myself Harshdeep Mehta, you can call me Harsh. I struck up in a situation where I need to define relative path in Web.Config. I.e. suppose I have a "Export" named folder, besides...
5
by: _DG | last post by:
At least when you've got any docs in .CHM format in the folder tree. If you drop a file called CSharpDocs.chm into a folder: \toplevel\C#\docs, you can open it, but it won't display. The #...
1
by: Darren | last post by:
I'm trying to create a file using drag and drop. I want to be able to select a listview item drag it to the shell and create a file. Each icon in the listview represents a blob in a database. When...
6
by: jzdeng | last post by:
Hi, All I use VS 2005 to create a web service. The web service is used to create a sheared folder. It works fine we I run it from VS 2005. But, when I move it to inetpub, it does not work...
2
by: Jason Gyetko | last post by:
I'm trying to open a file from VBA using a variable path and am not having very much luck. Can anyone help? This works: retval = Shell("""Excel.EXE"" ""C:\Program files\MyPath\MyFile.xls""",...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
7
by: ITAutobot25 | last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI...
1
by: Bassem | last post by:
Hi, I'm bulking an xml file using BULK statement to an XML variable, like this: DECLARE @xmlDoc XML SET @xmlDoc = ( SELECT * FROM OPENROWSET ( BULK 'D:\root.xml', SINGLE_CLOB ) AS...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.