0

I am in a situation where I have to download one file into Bytearray and make some changes in that byte array, also at the same time I have to download another large file and merge the first file into it with the modified bytes on the fly and play it using MediaElement.

Using Webclient I am able to download file but the webclient only gives me access to its dwonloaded bytearray when the file download is complete.

Is there a way to download the file and make modifications to the file's byte array on the fly in Silverlight.

I can not use Sockets, I can only download files from a Webserver.

Any help from you Gurus are appreciated

1
  • What do you mean by "on the fly"? That sounds like you think making changes to the downloaded content will make their way back to the server automatically... Any client/server communication will occur in chunks. WebClient is no different. You can do something with those chunks as they are received; but if you're expecting to get a byte at a time, that's not generally what happens with sockets. Jul 23, 2012 at 14:04

1 Answer 1

1

I can't see what is the problem with the Webclient.

You should copy the results of the WebClients in byte arrays. Once every file has been downloaded, you can merge those byte arrays.

byte[] bytes;
public void DownloadFile()
{
    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += (s, e) =>
       {
           Stream stream = e.Result;
           MemoryStream ms = new MemoryStream();
           stream.CopyTo(ms);
           bytes = ms.ToArray();
       };
    webClient.OpenReadAsync(new Uri("http://myurl.com/file.zip"), UriKind.Absolute);
}
2
  • That is my problem I can not wait for the 2nd file to be downloaded. My first file is only 150kb and the second file is about 400mb. The problem with webclient is you can access stream only when everything gets downloaded. Jul 27, 2012 at 12:50
  • I'm not sure I understand what you are trying to do. Can't you launch 2 WebClients at the same time? Could you be more precise about what you want to achieve? Jul 27, 2012 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.