You can also use .ini files to save info
API: WritePrivateProfileString, GetPrivateProfileString
I'm making a program to save information for what data I have one disc's I have burned.
Basically, what I am doing is I title a disc and burn the pictures/videos on to the dvd, then I want to create a item in a combo box with that name and then I will have a text box show the names of the videos/pictures that I want on in the disc.
The problem is, I need the items to save in the combo box so that when I restart the programs, the items will still be there. I also would like to have an option to edit the names in case if I decide to change it, and if I decide to remove an item because maybe the disc broke or I made a new one with a different name, I would like to remove that item from the combo box.
A few ways to do this is using my.settings or using an XML file. My.settings never seems to save when I move my program or copy it to another location. So I would like to use a XML file, though I have never used an XML file nor do I know how to add and remove data from it. Anyone mind explaining how to do so?
This is kinda the idea of the program, though I'm probably going to change some things around:
I've found an example on CodeProject, https://www.codeprojec*****m/Articles/...ove-Create-XML
I have figured out how to add items to xml and read it. The only thing is, when the program loads, it only adds the most recent item from the XML file to the combo box.
So this is what I am using:
It just reads the first item off of the Root and adds it. So maybe I would have to create my own items after the root, but then I would have to load every item after that, and I would have to save every one separately, so I'm out of ideas.. any help?Code:Dim read As String read = Read_XML_Value_("\DiscInfo\Disc.xml", "/Root/", "Name") discsel.Items.Add(read)
Last edited by Cryptonic; 04-21-2013 at 11:35 AM.
You can also use .ini files to save info
API: WritePrivateProfileString, GetPrivateProfileString
Simple.
Read from the .xml file you're wanting to use. Also, save as a list where you would be able to read/write to; to later save the data back into the .xml file.
To edit, just edit the item of the list via the index of the item.
Code:dim xdoc as xdocument = xdocument.load(path) For Each xel In xdoc.Elements()(0).Elements() '### NextCode:<whatever> <item>item1</item> <item>item2</item> <item>item3</item> </whatever>
Last edited by Biesi; 04-23-2013 at 07:25 AM.
Cryptonic (04-23-2013)
Can you explain how to use this?
Only thing I got so far is Xml.XmlTextWriter.Create("C:\test.xml") o_o
This page wasn't too helpful - XmlTextWriter Class (System.Xml)
I also tried another code
But that replaces the same item as well.Code:Dim writer As New XmlTextWriter(directory, Nothing) writer.WriteStartElement("items") writer.WriteElementString("name", TxtBox1.Text) writer.WriteEndElement() writer.Close()
something like thatCode:dim enc as new system.text.unicodeencoding dim xwriter as new xml.xmltextwriter(directory, enc) with xwriter .writestartdocument() .writestartelement("whatever") '<whatever> .writestartelement("item") '<item> .writevalue("item1") 'item1 .writeendelement() '</item> .writestartelement("item") '<item> .writevalue("item2") 'item2 .writeendelement() '</item> .writeendelement() '</whatever> .close() end with
Cryptonic (04-24-2013)
Wouldn't that do the same as the other code I'm using? I'm trying to have an unlimitied ammount of values that can be entered by a user into an XML file. Then that data can be read when the program starts and entered it into the comx (damnit bo bo, go away >:O. Should be combo box). The thing is, if every name is different, you have to load it all seperatly (unless there's a way to do that).
Sorry if this is confusing, I'm trying to think this out while I'm at school
Thanks for all of your help so far.
Last edited by Cryptonic; 04-24-2013 at 09:54 AM.
Well, this won't be of much help and it's my first XML usage code.
It append "items" and add them attributes:
I'll see if I can make something for you in the mean time
Last edited by Jorndel; 04-24-2013 at 10:53 AM.
Cryptonic (04-24-2013)
This was something I did for an application, I probably wrote alot more then was really needed but I couldn't seem to get saving and resaving an xml file to work properly any other way.
Saving the file
Reading in the fileCode:Private Sub saveCleaningLocations(ByVal folderPath As String) Dim writestart As Boolean 'If file doesnt exist then set write to true If IO.File.Exists("CleaningLocations.xml") Then Dim currentXMLDocument As New XmlDocument currentXMLDocument.Load("CleaningLocations.xml") Dim parentNode As XmlNode = currentXMLDocument.SelectSingleNode("Locations") Dim prodnode As XmlNode = currentXMLDocument.CreateNode(XmlNodeType.Element, "FolderPath", "") prodnode.InnerText = folderPath parentNode.AppendChild(prodnode) currentXMLDocument.Save("CleaningLocations.xml") Else writestart = True Dim xmlFile As IO.FileStream = New IO.FileStream("CleaningLocations.xml", IO.FileMode.Append) Dim xmlTextWriter As New XmlTextWriter(xmlFile, System.Text.Encoding.Default) With xmlTextWriter .Formatting = Formatting.Indented .Indentation = 3 .IndentChar = CChar(" ") If writestart Then .WriteStartDocument() .WriteStartElement("Locations") .WriteElementString("FolderPath", folderPath) .WriteFullEndElement() .Close() End With End If databind() End Sub
This was a copy and paste right from my app so you may have to pick what you need out of it, but as it is, it's working codeCode:Private Sub ReadCleaningLocations() If IO.File.Exists("CleaningLocations.xml") Then Dim documentClean As XmlReader = New XmlTextReader("CleaningLocations.xml") While (documentClean.Read()) Dim type = documentClean.NodeType If type = XmlNodeType.Element Then If documentClean.Name = "FolderPath" Then CreateRows(documentClean.ReadInnerXml.ToString) End If End If End While documentClean.Close() End If End Sub
Cryptonic (04-24-2013)
I have no idea how you're banned, but if you're not permanently banned, you used this for saving folder locations? And what did you insert the data to, a listbox?