tags:

views:

122

answers:

2

Hello,

I have an application that I am building that needs to modify a configuration file.

My problem is that I am not able to read the file in line by line. I keep geeting the the entire file as a single string.

string ConfigTemplate = AEBuildsSPFolderName + "\Template_BuildReleaseScript.Config";

string[] fileSourceLines = File.ReadAllLines(ConfigTemplate, Encoding.Default); -->Returns the entire file contents into the first array element.

using (StreamReader reader = new StreamReader(ConfigTemplate)) { string line; while ((line = reader.ReadLine()) != null) -->Returns the entire file contents into the first line read.

Any idea of what I am doing wrong?

Thanks,

david

A: 

Your file probably uses \n characters (without \r) as newlines.

SLaks
+3  A: 

I'm guessing the line break character used might not be \r\n

When you read your entire file into a single string, try calling yourString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); and see if that works for you.

Also since ReadAllLines() was just reading into a single string anyway, you could simply use ReadAllText().

Phong
Thank you for your response.Based upon your comments, here is a test code segment I put together...//Get File Linesstring[] fileSourceLines = File.ReadAllLines(ConfigTemplate, Encoding.Default);if (fileSourceLines.Length == 1){ string yourString = fileSourceLines[0]; string[] newSourceLines = yourString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); //This array still only contains 1 string.}newSourceLines array still only contains 1 string.Any other suggestions :)Thanks,david
David Dickerson
Ok, I just found that it was this problem..... Thank for everyones help!
David Dickerson