Solved

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

Posted on 2008-10-18
3
844 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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/…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now