What i try to do is saving XML document to stream, modifying it and saving a file on ftp. But after all these steps at the end of the file i get trash characters like 㼼浸敶獲潩㵮ㄢ… Where is the problem?
XmlDocument xmlD = (XmlDocument)xmlDocument.Clone();
byte[] fileContents = Encoding.Default.GetBytes(xmlD.OuterXml);
//ftpWReqUpload - FtpWebRequest to upload file
Stream requestStream = ftpWReqUpload.GetRequestStream();
xmlD.Save(requestStream);
ftpWReqUpload.ContentLength = fileContents.Length;
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
From what I see, you’re uploading the document twice. First you do
xmlD.Save()to the stream which will save your document in its original encoding, then you write a byte array that you got from the same document using the system default encoding. I suspect that if you just do something like;it will work.
Edit: I see @dasblinkenlight added a link to some working code to the comments to the question, you may want to take a look at that to get an idea how to handle the response.