I assume there must be a system and language independent way to just stick the "current" EOL character into a text file, but my MSDN-fu seems to be weak today. Bonus points if there is a way to do this in a web application that will put the correct EOL character for the current client's machine's OS, not the web server's.
views:
228answers:
5
+1
A:
Open the text file, seek to the end, and append Environment.NewLine.
DannySmurf
2008-09-24 23:05:35
+1
A:
You are looking for Environment.NewLine
. This will only be for your current operating system however.
Aydsman
2008-09-24 23:06:23
+2
A:
For the bonus point:
- Check the user-agent of the client machine, for substrings such as Windows, or Linux
- The System.Environment.NewLine for Windows is 0x13, 0x10; in unix, it's generally 0x10 only;
- Choose the appropriate newline string, append it to the line, and off you go
Silver Dragon
2008-09-24 23:09:24
+1
A:
For server-side code I would go for TextWriter.WriteLine. Detecting the OS of the client's machine requires browser sniffing - check Request.Browser.
korchev
2008-09-24 23:09:37