views:

45

answers:

1

Hi,

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

A: 

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.

ctacke
nope.. i tried the way you said.. its not working
Shadow
Have you compared the two files at a binary level to see where they actually differ? is it something at the end? Between packets? Knowing what the corruption looks like will help you figure out what it is.
ctacke
No, some time uploaded file will be just 1KB but source file will be 30KB... but i am able to read entire file through byte array.. can you check my code one more time
Shadow
ya.. i changed to byte as you said no use :-(
Shadow