i need to download a big data from the server,because the data is so big,i am not able to download it at a time,do you have any idea?Thanks you very much.
-
1How big is the data? What have you tried so far? What format is the data in? – Paul Diston Apr 16 '12 at 15:34
-
Thank for your reply,I wanna develop a windows phone 7 app that can watch and resume downloading movies online,so the size of movie depends on circumstances,most of time,it is more than 300 megabytes ,less than 1.5 gigabytes,and the format caintains mp4,wmv etc. – Apr 17 '12 at 07:11
3 Answers
The only logical way I can think about doing it is to pre-arrange the data into chunks for download with index. The index increments with the number of chunks received, so when the server sends down the file, it knows it can skip (chunkCount * chunkSize)
from the byte stream and begin sending down the next chunkSize
bytes.
Of course, this would mean a rather excessive number of requests, so YMMV.

- 40,736
- 10
- 68
- 86
-
Thanks,Dividing the data into chunks seems inappropriate for me,which may result in maintaining its source difficult and also the individual chunk may not download fully at a time unless the chunk is as small as possible,if so,there is a need to recreate the WebRequest again and again,which would consume lots of resource.Still thank you anyway. – Apr 17 '12 at 10:55
If the server supports it, you can use HTTP byte ranges to request specific parts of the file.
This page describes HTTP byte range requests: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1
The following code creates a request which will ask to skip the first 100 bytes, but return the rest of the file:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://example.com/somelargefile");
request.Headers.Add("Range", "bytes=100-");

- 7,679
- 2
- 47
- 80
-
No problem! don't forget to accept the answer if you think it's the right answer! – Ian Newson Apr 17 '12 at 07:39
-
I've read these articles carefully,it seems that they are dedicated to handle the the resuming downloading on the server side,actually,at this stage,i need to handle it on the client side,and also,WP7 does't support the AddRange method of WebRequest,what is your idea? – Apr 17 '12 at 10:36
-
This method is meant for the client side (e.g. the requestor), although it can be called on a server. I've updated my answer with some example code. – Ian Newson Apr 18 '12 at 09:28
-
Lan Newson,Very appreciate your help,the Http.Headers in wp7 dosen't have the Add method,i change it to request.Headers["Range"] = "100-",though i have not see the result yet maybe it is due to the slow network,it did throw any error. – Apr 18 '12 at 14:28
-
When you get the request back the response code should be 206. If it's not then the server doesn't support byte ranges. – Ian Newson Apr 18 '12 at 18:11
-
Sorry,i made a mistake,i lost a word of "not" in this "it did throw any error" sentence,that is "it did not throw any error".you are right,i would test that whether the server supports range download first.there are much limit of HttpWebRequest in wp7,if i figure it out,i would post it here.Thanks. – Apr 19 '12 at 04:46
There is a Background Transfer Service code sample on MSDN that might help. I've never used it, but the sample might give you a place to start from.

- 2,216
- 14
- 21
-
Hey,man,i have to say thanks to you specially ,you did me a great favor as well. – Apr 19 '12 at 14:22