473,326 Members | 2,128 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,326 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 7076
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.