• You could achieve this in SSIS without any C# coding. This is a rough outline of what is involved.
    Use the Execute SQL Task to get a Distinct List of Types and set the option to create a Full Result Set.
    Use a For Each Loop Task set to Foreach ADO Enumerator, create package variables to map to the fields in the Result Set
    Create a File System Task inside the Foreach Task to create the directories from the data you can now read from the variables, you can use an Expression Task to help build folder and file paths.
    Add a Data Flow Task to the Foraech Task
    Add an OLE DB Data Source to read the data for the file using parameters to filter for the current Type and Folder Number and use FOR XML in your SQL query to output to XML
    Add a Flat File Destination to the Data Flow using the variable data to set the file name.