Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

read flat file

Posted on 2007-08-09
4
Medium Priority
?
319 Views
Last Modified: 2010-04-15
I am trying to read a fixed width flat file from C# code, any ideas ?
0
Comment
Question by:saswati_m
4 Comments
 
LVL 13

Expert Comment

by:iHadi
ID: 19667460
if you mean a text file:

string str = File.ReadAllText("File_Path");
Messagebox.Show(str);
0
 
LVL 2

Accepted Solution

by:
felipecsl earned 375 total points
ID: 19667502
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
 
LVL 1

Expert Comment

by:winsoftech
ID: 19667803
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19668580
Dog pile!!!

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

Bob
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question