views:

362

answers:

5

I have to create a CSV file that represents an order.

The file is going to be FTP'd over, and imported into another system.

What line feed/carriage return character should I use?

I am pretty sure the receiving end will be a microsoft system, is there a way to make it server agnostic?

+2  A: 

Using only newlines (LF, '\n', chr(10), ^J, etc.) is supported by all operating systems. Individual applications vary in handling, especially in the Microsoft world.

Operating systems which internally use the CR LF pair—such as MSDOS, Windows, OpenVMS in stream_CRLF mode, etc.—are able to deal with LF-only.

Within FTP, use the ascii command for it to do the right thing with your file.

wallyk
"Using only newlines (LF, '\n', chr(10), ^J, etc.) is supported by all operating systems." - is is true that Windows knows what an LF is, but it is how a consuming app behaves that is important. Many windows apps only recognise CR+LF as a newline, e.g. Notepad.
AdamRalph
A: 

Unfortunately you will have to make a choice between MS or non-MS/Unix(y) newlines.

MS is CR+LF, non-MS is just LF.

More info here http://en.wikipedia.org/wiki/Newline

On MS systems, many apps may well interpret an LF newline correctly, but some will not, e.g. Notepad. If you want to guarantee that all MS based apps will interpret your newlines correctly then you will have to use CR+LF, but this will come at the expense of double new lines in some apps on a non-MS system (some apps on a non-MS system will interpret CR+LF as a single newline).

AdamRalph
A: 

If your destination is a Microsoft Windows system, use CR+LF, which is the native Windows end of line.

Mox
+2  A: 

Use the default for whatever server creates the file. With FTP, transfer the file in text mode (the default mode, IIRC). It automatically converts line endings on the receiving side.

In summary, you do not need to do anything special. FTP already handles it in a server agnostic fashion.

Robert Wohlfarth
+2  A: 

You should to use System.Environment.NewLine, or ask for directions to that external application staff.

Rubens Farias