Txt file Query
Hi All, I have one requirement which is basically on text file data.I have a package where i dumping data from a table to text file.Now the text file which is been genarated ll be used by the application.Now the Problem is whenver the application tries to import or use this generated text file their a one more line or a row that is getting generated due to the placement of pointer to next line i.e if my data generated in txt file is a,b,c d,e,f then the pointer shud be placed after f but as of nw whenevr we open the txt file the pointer ll pointing to place \below d which is causing for a new row. Please advice me to get rid of this pointer such that it is placed after f instead below D Thanks SanthoshPlease have look on the comment
August 30th, 2012 6:00am

You need to remove the final row delimiter (usually <cr><lf>) from the file. SSIS adds this automatically, so I would use a script task to open up the file, go to the end and remove those special characters. Here's an example (in Powershell though, but it shows the algorithm): http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/20/how-can-i-remove-the-last-carriage-return-linefeed-in-a-text-file.aspxMCTS, MCITP - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2012 6:06am

Hi Koen, Thanks But since i am not a .Net developer i just need help for using the code given in the link suggested in you reply. Kindly request you to help me out on this. ThanksPlease have look on the comment
August 30th, 2012 6:13am

Put a script task in your control flow and put the following code in: public void Main() { string fileData = System.IO.File.ReadAllText(@"Path"); if (fileData.EndsWith(Environment.NewLine)) { System.IO.File.WriteAllText(@"Path", fileData.TrimEnd(Environment.NewLine.ToCharArray())); } Dts.TaskResult = (int)ScriptResults.Success; } Remember @"Path" is the file path of where you have dumped your text file. Pass this file name using a variable. What the above code does is reads all text from the file, check for the prescence of a carriage return at the end of the file and if it exists strips it off.http://btsbee.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2012 6:46am

Put a script task in your control flow and put the following code in: public void Main() { string fileData = System.IO.File.ReadAllText(@"Path"); if (fileData.EndsWith(Environment.NewLine)) { System.IO.File.WriteAllText(@"Path", fileData.TrimEnd(Environment.NewLine.ToCharArray())); } Dts.TaskResult = (int)ScriptResults.Success; } Remember @"Path" is the file path of where you have dumped your text file. Pass this file name using a variable. What the above code does is reads all text from the file, check for the prescence of a carriage return at the end of the file and if it exists strips it off. http://btsbee.wordpress.com/ thank u so much this wrked for me.Please have look on the comment
August 30th, 2012 7:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics