• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

read flat file

I am trying to read a fixed width flat file from C# code, any ideas ?
0
saswati_m
Asked:
saswati_m
1 Solution
 
iHadiCommented:
if you mean a text file:

string str = File.ReadAllText("File_Path");
Messagebox.Show(str);
0
 
felipecslCommented:
Additionally, you could read it line by line:
StreamReader sr = File.OpenText(filename);
for (; ; )
{
       string line = sr.ReadLine();
       if (line == null)
       {
              break; // end of file
       }
}
0
 
winsoftechCommented:
C#
--------------------------------------------------------------------------------------------------------------------------------------------------      StreamReader sr=new StreamReader(FilePath);
      Header=sr.ReadLine();
      string Detail=String.Empty;
        while(sr.Peek()>=0)
         {
             Detail=sr.ReadLine();
         }
      sr.Close();
                MessageBox.Show(Detail);
0
 
Bob LearnedCommented:
Dog pile!!!

string[] lines = File.ReadAllLines("File_Path");

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now