Streamwriter inserting blank lines

Asked

Viewed 268 times

0

I am implementing the download of a file in ofx, I am generating the string and then adding to a Streamwriter, but if I add row by row or add the entire string at once without breaking lines, it creates a multi-line file at the blank end, after the contents of the string, follows the code:

string ofx = metodoQueRetornaString();
MemoryStream stream = new MemoryStream();
StreamWriter file = new StreamWriter(stream, Encoding.UTF8, 512);
file.Write(ofx.Replace("\n", file.NewLine));
file.Flush();
file.Close();

The string ofx returns with something like:

OFXHEADER:100\n<OFX>\n<INFORMAÇÕES DO OFX>\n</OFX>

You should create a file with the content:

OFXHEADER:100
<OFX>
<INFORMAÇÕES DO OFX>
</OFX>

You are creating a file with this content:

OFXHEADER:100
<OFX>
<INFORMAÇÕES DO OFX>
</OFX>






`

Note: I put these accents only to represent the empty lines.

  • I could not understand what the problem is. It has how to edit and put an example simple how the file should be and how it is getting? And also, how is the string with the content.

  • Look, I just created an application with this code of your question and everything works normally. My tip is to check the return of this method to see if it doesn’t add.

  • Okay, I’ll check, thanks

  • @jbueno got it, I sent an array of bytes straight, without going through the stream, I think it was a bug of memoryStream or Streamwriter

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.