Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with merging files

Hi,

I'm using the code below to merge file for multiple countries, how do I modify it to avoid duplicating the code for each country?
fsItem= New System.IO.FileStream(Application.StartupPath + "\LinkFiles\LinkFinalMain.xml", IO.FileMode.Open)
        dtsetItem.Clear()
        dtsetItem.ReadXml(fsItem)
        fsItem.Close()
        Dim DestinationPath As String = IO.Path.Combine(Application.StartupPath + "\LinkFiles\", IO.Path.GetFileName("\LinkFiles\LinkFinalBEL.xml"))

        If IO.File.Exists(DestinationPath) Then
            fsReceiver = New System.IO.FileStream(Application.StartupPath + "\LinkFiles\LinkFinalBEL.xml", IO.FileMode.Open)
            dtsetReceiver.Clear()
            dtsetReceiver.ReadXml(fsReceiver)
            dtsetItem.Merge(dtsetReceiver, True, MissingSchemaAction.AddWithKey)
        End If
        '  MsgBox(dtsetItem.Tables(0).Rows.Count)
        Dim DestinationPathA As String = IO.Path.Combine(Application.StartupPath + "\LinkFiles\", IO.Path.GetFileName("\LinkFiles\LinkFinalCAN.xml"))
        If IO.File.Exists(DestinationPathA) Then

            fsDonor = New System.IO.FileStream(Application.StartupPath + "\LinkFiles\LinkFinalCAN.xml", IO.FileMode.Open)
            dtsetDonor.Clear()
            dtsetDonor.ReadXml(fsDonor)
            fsDonor.Close()
            dtsetItem.Merge(dtsetDonor, True, MissingSchemaAction.AddWithKey)
        End If

        Dim DestinationPathB As String = IO.Path.Combine(Application.StartupPath + "\LinkFiles\", IO.Path.GetFileName("\LinkFiles\LinkFinalCZE.xml"))
        If IO.File.Exists(DestinationPathB) Then
            fsDonor = New System.IO.FileStream(Application.StartupPath + "\LinkFiles\LinkFinalCZE.xml", IO.FileMode.Open)
            dtsetDonor.Clear()
            dtsetDonor.ReadXml(fsDonor)
            fsDonor.Close()
            dtsetItem.Merge(dtsetDonor, True, MissingSchemaAction.AddWithKey)
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I should note that my code assumes there's no particular reason that one of the files is read into dtsetReceiver and the other two are read into dtsetDonor. If those are significant outside of the code snippet here, then you'll need to have a way to reference them by subscript, such as:
        Dim dt(2) as DataSet
        dt(0) = dtsetReceiver 
        dt(1) = dtsetDonor
        dt(2) = dtsetDonor

Open in new window

and then change all the references from dtsetReceiver to dt(iCountry).
Avatar of Victor  Charles

ASKER

Thank You, I will try it and get back to you.
Thank You.