load multiple xml file into a single flat file destination

  • hi guys

    i need help, i've created a ForeachLoop Container which loop through all the files .xml in my source directory then created XML Source and flat file Destination, my package execute successfully but create multiple output .txt file instead i one to output in one single .txt file

    thanks

  • What is the connectionstring set to in the connection manager for the output file? I can't see how you can get multiple files unless you're renaming dynamically during the loop.

  • thank you for the response

    here's my output path C:\OnKeyImports\WorkOrderCosting\Source\WorkOrderCosting_20130419_100035.txt

    the expression on the connection string is @[User::ImportSourcePath] + @[User::FilePrefix] + "_" + (DT_WSTR,4)DatePart("yyyy", GetDate()) + RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) + "_" + RIGHT("0" + (DT_WSTR,2)DatePart("hh", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("mi", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("ss", GetDate()), 2) + @[User::FileExtension]

  • Are you getting multiple files with different times in the name, or are you getting a single file which is being overwritten each time round the loop?

  • i'm getting multiple files outputs whereas i want to combine all my input to a single file.

    here's what i'm doing. i have multiple files e.g Item1.xml, Item2.xml, Item3.xml, etc. these files have same format field , i created Foreach Loop container inside the container i have a dataflow which has xml source and Flat File Destination.

    the destination should be a single file which combines data coming from the xml source instead i'm getting multiple outputs.

    thanks

  • The only way I can see you getting multiple files from that connectionstring is if it was taking more than a second to process each file. Each time you go round the loop, it will rebuild the connection string, and will give it a different name because the seconds part will differ.

    I would try building the filename into a new variable before entering the loop and then using that variable in the connectionstring.

  • (and obviously make sure you've got Overwrite=False in the Flat File Destination properties - I think that the default is True).

  • i've build connection path variables -

    ImportSourcePath = C:\OnKeyImports\WorkOrderCosting\Source\

    FilePrefix = WorkOrderCosting

    FileExtension = .txt

    and build it in the connection string like this to add date in the file name:

    RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) +

    "_" + RIGHT("0" + (DT_WSTR,2)DatePart("hh", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("mi", GetDate()), 2) +

    RIGHT("0" + (DT_WSTR,2)DatePart("ss", GetDate()), 2) + @[User::FileExtension]

  • Yes, but it will recalculate that connectionstring every time it uses it (i.e. every time round the loop).

    Create a new variable User::FullOutputFileName (or whatever), and assign its value as:

    RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) +

    "_" + RIGHT("0" + (DT_WSTR,2)DatePart("hh", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("mi", GetDate()), 2) +

    RIGHT("0" + (DT_WSTR,2)DatePart("ss", GetDate()), 2) + @[User::FileExtension]

    before entering the loop. (You'll probably need to do this in a script to ensure it gets the actual value rather than just the formula).

  • Andrew Watson-478275 (4/19/2013)


    Yes, but it will recalculate that connectionstring every time it uses it (i.e. every time round the loop).

    Create a new variable User::FullOutputFileName (or whatever), and assign its value as:

    RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) +

    "_" + RIGHT("0" + (DT_WSTR,2)DatePart("hh", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("mi", GetDate()), 2) +

    RIGHT("0" + (DT_WSTR,2)DatePart("ss", GetDate()), 2) + @[User::FileExtension]

    before entering the loop. (You'll probably need to do this in a script to ensure it gets the actual value rather than just the formula).

    Another way of doing this is to have a static name for the output file and then to rename it after the data flows have all completed.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Good point Phil. Probably neater to do it that way (and no need for any scripts).

  • i've tried creating a static output file but now only one file is loaded in the the destination

  • Have you configured the output as 'Append' or 'Overwrite'?

    If only the final file is appearing in there, I would suspect 'Overwrite'.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • YOU ARE SUCH A STAR

    thank you so much i didn't realize i was overwitting the ouput, it works perfectly now!!!!!

  • Great - thanks for that!

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply