Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

11 Experts available now in Live!

Get 1:1 Help Now