c# - StreamWriter add an extra \r in the end of the line -
i created class responsibility generate text file each line represents information of object of 'mydataclass' class. below simplification of code:
public class generator { private readonly stream _stream; private readonly streamwriter _streamwriter; private readonly list<mydataclass> _items; public generator(stream stream) { _stream = stream; _streamwriter = new streamwriter(_stream, encoding.getencoding("iso-8859-1")); } public void generate() { foreach (var item in _items) { var line = anotherclass.getlinefrom(item); _streamwriter.writeline(line); } _streamwriter.flush(); _stream.position = 0; } }
and call class this:
using (var file = new filestream("name", filemode.openorcreate, fileaccess.readwrite)) { new generator(file).generate(); }
when run application on visual studio (i test run (ctrl+f5), debug (f5), debug , release mode) goes according plan. publish application in iis server , streamwriter class put \r before end of line.
check out hexadecimal reading of both generated files:
running in visual studio: http://www.jonataspiazzi.xpg.com.br/hex_vs.bmp
running in iis: http://www.jonataspiazzi.xpg.com.br/hex_iis.bmp
some things checked:
write
line
variable (invar line = anotherclass.getlinefrom(item);
) in log see if '\r' uncluded classanotherclass
.
didn't result in nothing, last char in line
regular char expected (in example above space).
write code see if problem general iis streamwriter instances.
i tried this:
var ms = new memorystream(); var sw = new streamwriter(ms, encoding.getencoding("iso-8859-1")); sw.writeline("test"); sw.writeline("of"); sw.writeline("lines"); sw.flush(); ms.position = 0;
in case code works both visual studio , iis.
i'm in 3 days, try brain can think. did have clue can try?
update
get weirder! try replace line _streamwriter.writeline(line);
with:
_streamwriter.write(linhatexto + environment.newline);
and worse:
_streamwriter.write(linhatexto + "\r\n");
both keep generating \r
character.
i try replace this:
_streamwriter.write(linhatexto + "#\r\n#");
and get:
my guess \r added during ftp (maybe try binary transfer)
like here
i've tested code , /r not due code in current question
Comments
Post a Comment