Solved

How to read each line of a text file from a C# web app

Posted on 2008-10-18
3
861 Views
Last Modified: 2012-05-05
I am using a ajax enabled asp 2.0 page in VB.net 2005 page in C#

I need to have my program to read each line of a text file and after that line store that information into a variable then continue to the next line and repeat. please help thanks!
0
Comment
Question by:Figle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:brenkehoe777
ID: 22749843
Try this:
StreamReader sr = new StreamReader("c:\\blob.txt");
 
            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
            }

Open in new window

0
 

Author Comment

by:Figle
ID: 22750389
sorry about the delayed response, work is crazy today and thanks but this only puts the last thing in the text file into the variable, thats where i am stuck at. I am going to post with a better idea of what i need.

0
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 22750623
use the following code

using System.IO;

string[] data = File.ReadAllLines("path_to_file");
foreach (string s in data)
{
     StoreMyData(s);
}
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Silverlight ERP To Angularjs,HTML5 3 60
Asp.net 4 FileUpload gets "Permission Denied" when Uploading file 8 36
window close link 7 35
Html split(text) Part2 6 23
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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