I have a directory of Excel files that includes the date in the file name; they represent reports. I have already imported all the data into sequel server from the excel files but need to attach the date from the File Name to each of those records that were imported into Sql-Server.
Example Dir List.
A_201008.xls
A_201009.xls
A_201010.xls.........
The following is my C# ScriptTask to fill an array of File Names:
usingSystem;usingSystem.Data;usingMicrosoft.SqlServer.Dts.Runtime;usingSystem.Windows.Forms;usingSystem.IOpublicvoidMain(){// TODO: Add your code herestring[] files =Directory.GetFiles(@"\\S\Apps\Files\", "A*.xls*", SearchOption.AllDirectories); int Flag = 0; string dir = @"\\S\Apps\Files\";string[] files1;int numFiles; files1 =Directory.GetFiles(dir); numFiles = files.Length;for(int i =0; i < numFiles; i++){string file = files[i].ToString();int file1 = file.IndexOf(dir,StringComparison.CurrentCultureIgnoreCase);if(file1 !=-1){MessageBox.Show(file);Flag=1;}}
if(Flag==0){MessageBox.Show("No Matches Found");}Dts.TaskResult=(int)ScriptResults.Success;}
The MsgBoxes are the just for testing the script and will be removed.
My question is this. What is the protocol in SSIS to grab the File Names from my array to insert them in the relevant rows of my table in SQL-Server?
Please Note that I already know what to do to trim the file names for the date.
Thanks