Here is the snippet which can be used to count total columns in your flat file. Below script assume that you have column count based on separator=comma. if you use different separator then just change script accordingly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public void Main() { // TODO: Add your code here var colCnt = GetFileColumns("file1",','); MessageBox.Show("Your file has total " + colCnt + " columns"); Dts.TaskResult = (int)ScriptResults.Success; } private int GetFileColumns(string connName,char colSeperator= ',') { var filePath=Dts.Connections[connName].ConnectionString; string firstline; using (System.IO.StreamReader sr = new System.IO.StreamReader(filePath)) { firstline= sr.ReadLine(); } var colArr=firstline.Split(new char[]{colSeperator}); return colArr.Length; } |