Link to home
Start Free TrialLog in
Avatar of claghorn
claghorn

asked on

Format and write a .net dataset to fixed length file format.

I have a result set in a C# console app. I want to write each row to a fixed length file. ie: each resultset element will take x amount of spaces that I define. How do you do this in C#?
ASKER CERTIFIED SOLUTION
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of claghorn
claghorn

ASKER

close, but it does not terminate each line in the resulting file. ie: the line continues infinitem. btw putting "\n" puts a space between each line and does not terminate each line either. Can you suggest the rest for a full soultion?
The string, "\r\n", should terminate the line.
Thanks, but no luck. It does not terminate the line. ie: if you cursor (right arrow) over the line it continues beyond.
Also, the lines are spaced now.
I always did get the return to next line when not specifying the "\r\n", but again, the line continues beyond the end.
The file does not behave like a main frame generated file that, when you cursor through it, it returns you to the next line.

Lines cannot possibly continue beyond the end.
The end is, by definition, the point beyond which the line does not continue.
The most likely explanation is that the lines does not end where you expect them to, i.e. you have padded the last field of the record out with spaces.
Did you have any luck with this ?
If I try to put a \r or \n, I get a space separating each line. This is unwanted. I want to be able to scroll through each line and where the data ends, find myself at the beginning of the next line.  
OK. Is it possible that you are creating the record adding a \n or a \r (or both) to the end of it and then using the WriteLine() method of some stream/file/text writer that is appending another \r\n to the end of the line ?

It would be useful if you showed your code but to be honest for a 20 point question you can't expect miracles.
The best you can hope for for 20 points is to be pointed in the right direction and if you are lucky some pseudo-code.
It's a bit much to then go and give a B grade because you can't get the linefeeds to work.
Use System.Environment.NewLine, not "\r\n"