C # File.ReadAllLines not breaking in lines

I have an application that I create to modify a configuration file.

My problem is that I cannot read the file in a string sequence. I save the whole file as a separate line.

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 what I'm doing wrong?

Thank,

David

+5
source share
2 answers

I assume the line break character used cannot be \r\n

When you read your entire file in one line, try calling yourString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);and see if this works for you.

Also, since I ReadAllLines()just read on one line, you could just use ReadAllText().

+5
source

, , \n ( \r) .

0

All Articles