المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : FtpWebRequest - (UploadFile) every other character is NULL



C# Programming
05-07-2010, 02:33 AM
...here is the relevant code code:
private static void WriteArchive(string document, MessageType outboundInfo, string filePath, FtpWebRequest request)
{
try {
using (MemoryStream memoryStream = new MemoryStream(document.Length))
{
//configure a buffer for reading data after document is streamed
int bufferSize = document.Length;
byte[] buffer = new byte[bufferSize];
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] _document = encoding.GetBytes(document);

//stream document and reset memoryStream's internal position pointer
memoryStream.Write(_document, 0, _document.Length);
memoryStream.Seek(0, SeekOrigin.Begin);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = true;
request.UseBinary = false;
request.KeepAlive = false;
using (Stream stream = request.GetRequestStream())
{
//now pointing to the FtpWebRequest's internal stream
int content = memoryStream.Read(buffer, 0, bufferSize);
while (content != 0)
{ //write contents of memoryStream out to FtpWebRequest
stream.Write(buffer, 0, content);
content = memoryStream.Read(buffer, 0, bufferSize);
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}

When I stepped through, there were 2 executions of the loop. I was kind of puzzled by it, because I had set the buffersize to accept the whole enchilada. So, I stepped through again, and on memoryStream.Read, every other byte inside buffer is '0' . ...After the file was written, I opened it up in Notepad++ and confirmed that NULLS were being inserted into the file. Did I just do something stupid? Anyone know how to cull those NULL characters?
"I need build Skynet. Plz send code"