Last post Jul 12, 2012 09:31 PM by Decker Dong - MSFT
Jul 11, 2012 09:18 AM|sharma.dhiraj87|LINK
I have to read a text file index wise by using Stream Reader Class... but that class do not provide any predefined method by which i can read the Record index wise.... Please help me how to do that.....
Jul 11, 2012 09:46 AM|MattsDotNetUsername|LINK
If your file is fixed width, you can use Seek() mentioned in the link below. If it is not fixed width, you could load the entire file (if it is not too big) and just use an array. There is an example below.
String filePath = ".\\MyFile.txt";
FileInfo myFile = new FileInfo(filePath);
using (FileStream stream = myFile.Create())
using (StreamWriter writer = new StreamWriter(stream))
String allLinesInFile = File.ReadAllLines(filePath);
Jul 12, 2012 09:31 PM|Decker Dong - MSFT|LINK
but that class do not provide any predefined method by which i can read the Record index wise.... Please help me how to do that.....
To read a plain text file is quite different from reading from a certain database. So I think you have to use something like System.IO.File.ReadAllLines to read all things into a string collection, and then assign the index to access a certain string from
the string group.