Wednesday, February 10, 2010

Read Files From Folder

 A) Create String Variable “SourcePath” for the Source Folder and Assign Value C:\DatFiles\Pending
B) Select Script Component from Transformation Control and choose the “Source Option” and
Edit Script component and set Read Only Variable like here.


1.       Create OutPut Columns and set the datatype to hold the Out put rows
3    a) Read File Names from Folder using VB.Net or C#.NET
public override void CreateNewOutputRows()

      {



               

        string folderPath = "";

        // Asign Package Variable Path to local Variable

        folderPath = Variables.SourcePath;

        DirectoryInfo dir = new DirectoryInfo(folderPath);

        if(dir.Exists)

        {

            if (dir.GetFiles().Length > 0)

            {

                FileInfo[] dirFiles = dir.GetFiles();

                foreach (FileInfo fiInfo in dirFiles)

                {

                    SourceFilesBuffer.AddRow();

                    SourceFilesBuffer.FileName = fiInfo.Name;

                    SourceFilesBuffer.CreatedDate = fiInfo.CreationTime;

                }

            }           

        }    

b) Write OutPut in to OLEDB Table like step 1. B)


4.       A) Create Source File and Pending Files Variables for Load Current Filename  and Hold All Filenames Respectively
b) Select Source Filenames from OLEDB Table and Assign Rows into PendingFiles Object Variable
Using Execute SQL Task Editor

Please refer the URL….



5.       Read Pending Files from collection Object and Assign Current File Name in to SourceFile Variable



6.       Assign Variable Name in to Source File Connection
Note: If you assign only the Variable Name in the Connection String then it will work in Development Environment. It won’t work in Production. So specify the File Path With \\



I Hope this will Help you to Read Files from folder Using Script component Source and do the looping over the files using For Each Loop.



No comments: