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 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:
Code:
Dim read As String
read = Read_XML_Value_("\DiscInfo\Disc.xml", "/Root/", "Name")
discsel.Items.Add(read)
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?
Yea, but ini files are more for settings... XML's are more for data. But really confusing ._.
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.
Originally Posted by DawgiiStylz
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.
I have that idea down.. stated in op. I'm stuck on how to load multiple items from an xml.
Code:
dim xdoc as xdocument = xdocument.load(path)
For Each xel In xdoc.Elements()(0).Elements()
'###
Next
Dim writer As New XmlTextWriter(directory, Nothing)
writer.WriteStartElement("items")
writer.WriteElementString("name", TxtBox1.Text)
writer.WriteEndElement()
writer.Close()
But that replaces the same item as well.
Originally Posted by PepsiXHacker
Can you explain how to use this?
Code:
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
something like that
Originally Posted by Biesi
Code:
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
something like that
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.
Well, this won't be of much help and it's my first XML usage code.
It append "items" and add them attributes:
Nooby Code
I'll see if I can make something for you in the mean time
Originally Posted by Jorndel
Well, this won't be of much help and it's my first XML usage code.
It append "items" and add them attributes:
Nooby Code
I'll see if I can make something for you in the mean time
This is what it created with that code
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
Code:
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
Reading in the file
Code:
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
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 code
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?