I have the code below in my project, my project generates an error on the ReadXml line, I have added a new Xml file to my project and renamed it to data.xml, how do I in the ReadXml line refer to the Xml file in my project ?
Dim ds As New DataSet
ds.ReadXml("data.xml")
Dim dt As DataTable = ds.Tables("stock")
' Add Row
Dim row As DataRow
row = dt.NewRow()
row("electrician") = electrician.SelectedItem
row("item") = item.SelectedItem
row("quantity") = quantity.Text
row("unitcost") = unitcost.Text
dt.Rows.Add(row)
' Write data back to xml file
ds.WriteXml("data.xml")
This is the error I recieve :
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.xml.dll
Additional information: Could not find file "D:\Programming\Visual Basic Net\VB Projects\DSR\bin\data.xml".
I expected when I added the Xml file to my project for it to be in the bin folder which is where the runtime code is kept but it not, its in the folder outside the bin folder.
When I build the program the Xml file does not get copied into the bin folder so the program can't find it.
Any help on how to reference my xml file in my project would be greatly appreciated ?
Question
Large
I have the code below in my project, my project generates an error on the ReadXml line, I have added a new Xml file to my project and renamed it to data.xml, how do I in the ReadXml line refer to the Xml file in my project ?
Dim ds As New DataSet ds.ReadXml("data.xml") Dim dt As DataTable = ds.Tables("stock") ' Add Row Dim row As DataRow row = dt.NewRow() row("electrician") = electrician.SelectedItem row("item") = item.SelectedItem row("quantity") = quantity.Text row("unitcost") = unitcost.Text dt.Rows.Add(row) ' Write data back to xml file ds.WriteXml("data.xml")This is the error I recieve :
I expected when I added the Xml file to my project for it to be in the bin folder which is where the runtime code is kept but it not, its in the folder outside the bin folder.
When I build the program the Xml file does not get copied into the bin folder so the program can't find it.
Any help on how to reference my xml file in my project would be greatly appreciated ?
Kind Regards
Edited by LargeLink to comment
Share on other sites
6 answers to this question
Recommended Posts