Question : How to read the last line of a Text file

Here is some background. I am using VS 2008 Visual Basic in a Windows Forms project to do a BULK import from a text file into SQL server. This bulk import will fail if the last line of the text file is blank. There are over 200,000 lines in the text file. i don't want to read and check each one.
How can I advance to the end of the file and check the last couple of characters? I am thinking I have to check for Chr(13) and/or chr(10).

thanks,
pat

Answer : How to read the last line of a Text file

I believe you can not TRIM last line of file until and unless you fetch file into memory. You can read a part of file and write into file(this will either truncate file first or append the file) but there is no  option for REPLACE in file without bringing it into memory. you need  to read all lines, and make changes and then write it back.

How you pass the file to SQL. You pass it from vb.net OR read it from SQL directly ??
So, it may possible that I could help you on that.

-Shahan



 

Random Solutions  
 
programming4us programming4us