Where is Problem in my code to upload a file to server from windows mobile
i have problem of uploading zip file ot server from my windows mobile.. in server the .zip file is getting created,if i open file its telling unable to open and its corrupted
here is code
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
// Retrieve request stream and wrap in StreamWriter
Stream reqStream = req.GetRequestStream();
StreamWriter wrtr = new StreamWriter(reqStream);
// Open the local file
StreamReader rdr = new StreamReader(localFile);
// loop through the local file reading each line
char[] buff = new char[1024];
int inLine = rdr.Read(buff, 0, 1024);
//int inLine = rdr.ReadBlock (buff,0,1024);
while (inLine > 0)
{
wrtr.WriteLine (buff);
inLine = rdr.Read (buff, 0, 1024);
}
rdr.Close();
wrtr.Close();
try
{
开发者_运维问答 req.GetResponse();
}
catch
{
}
reqStream.Close();
Thanks
The first problem I see is that you're always writing the entire contents of 'buff', not just the number of bytes read. Unless you file size is evenly divisible by 1024 that's a problem. It's also a problem in the even the read doesn't bring back a full 1024 bytes.
Update 1
THe second thing I question here is why are you using a char[] for holding binary data? That's just a bad practice all around. char is for string data (and char in CE is 2 bytes anyway). Use a byte[] for binary data - that's what it's for. It's quite possible that the current encoding is doing something like stripping the MSB off of data bytes because you're stuffing it into a char. It could also have to do with the size issue.
精彩评论