Introduction In some cases when you call API to http URL it may redirect you to different location (Also known as 301 or 302 redirect). Best example is when you type https://www.zappysys.com it will redirect you to https://zappysys.com. This can cause issue in some case if you are passing credentials (i.e. UserID / Password) because […]
Monthly Archives: May 2016
How to count file columns in SSIS using C# Script
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; } |