Well, I came up with solution that it is working eventhough I am not completed sure it is coded the right way: Public Sub FillAllWithXMLBasics(ByVal ValidationKey As String) '-- Establish Locals Dim lcFile As String = MicroFour.StrataFrame.Strings.StringBasics.AddBS(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) '-- Save the XML file to disk lcFile &= ConstantInformation.ServerSettingsXMLFileName
'-- Get all data columns from the TableSchema in the BO ' to pass it in the xmlBasics.OpenXmlFile Dim boTableColumnArray As New List(Of DataColumn) For Each I As DataColumn In Me.CreateTableSchema boTableColumnArray.Add(I)
Next '-- Load the XML file and add one row _myXMLDS = XmlBasics.OpenXmlFile(
"ConsoleSettings", lcFile, boTableColumnArray) If _myXMLDS.Tables("ConsoleSettings").Rows.Count = 0 Then _myXMLDS.Tables(
"ConsoleSettings").Rows.Add() End If '-- Move the data into the business object Me.CopyDataFrom(_myXMLDS.Tables("ConsoleSettings"), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable) '-- In this case we need only one record so ' if there is no record, add one here. If Me.Count = 0 Then Me.Add() Me.CurrentDataTable.AcceptChanges() End IfEnd Sub
In the above code I am not sure if I neede to create the boTableColumnArray or there is an easy way to pass the BO columns to the OpenXmlFile() method.
And to save the file from the BO to the XML I am using this method:
Private Sub SaveToXML() '-- Establish Locals Dim lcFile As String = MicroFour.StrataFrame.Strings.StringBasics.AddBS(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) '-- Save the XML file to disk lcFile &= ConstantInformation.ServerSettingsXMLFileName
'-- I am not sure if the file needs to be deleted
If System.IO.File.Exists(lcFile) Then
System.IO.File.Delete(lcFile)
End If '-- Remove the Row created in the FillAllWithXMLBasics and import the one from the BO.
'-- I guess there is probably a better way to do this?
_myXMLDS.Tables("ConsoleSettings").Rows.RemoveAt(0) _myXMLDS.Tables(
"ConsoleSettings").ImportRow(Me.CurrentRow) '-- Write the XML file back to disk. Notice that you DO NOT NEED the validation key ' to write back to disk. This is used only for opening (and the creation of) the XML table. XmlBasics.WriteXmlFile(_myXMLDS, lcFile,
False) Me.CurrentDataTable.AcceptChanges()End Sub
I appreciate if someone can review these code and confirm they are code appropriately.
Thanks!