My app writes the contents of text files to a db memo field. Most files display properly in the db form, but some display in a run-on fashion (all contents on one line). If I open these files in Wordpad they display correctly, so I save them as plain text to make them display properly in the db form.
I'm tired of doing this :-) and would like to perform this "conversion" programmatically. Using the "analyze the bom" method I found online, it says both types of files are ASCII. Trying to load a problem file into a RichTextBox as rich text returns "input file not in correct format". Using the immediate window in debug, I've found the files that display properly use \r\n for newline, and the ones displaying improperly use only \n. Using Regex.Replace \n, \r\n just causes the \r\n to appear visibly as text (rather than encoding characters). The question "Text shown in single line in notepad" seems to be the same type of issue, except the file is being streamed and massaged line-by-line, which I'm thinking shouldn't be necessary.
So... all I need to do programmatically is to somehow mimic the behavior of opening the file in Wordpad and overwriting it as plain text. I've experimented extensively (unsuccessfully) with Encoding.Convert and the thing that really baffles me, is that the problem files appear to be ASCII encoded just like the "good" files, only difference is that the good files use \r\n where the problem files use just \n. Any help is appreciated...
For what it's worth, this is the statement that's loading the text file contents into the temporary string array (whose contents are later loaded to db). I realize I might need to ReadAllText into a "work" string and massage it before loading it to the array... but the only massaging it needs is to be opened in Wordpad and then overwritten as plain text. If only I could figure out how to do that!
txtfileary[aryctr] = File.ReadAllText(textfile, Encoding.ASCII);