开发者

Read several byte from file via http c#

开发者 https://www.devze.com 2023-03-12 03:56 出处:网络
How to download开发者_如何学C first 200 bytes of a file via HTTP protocol using C#? I believed it could be done like this:

How to download开发者_如何学C first 200 bytes of a file via HTTP protocol using C#?

I believed it could be done like this:

WebClient wc = new WebClient();
byte[] buffer = new byte[200];
using (var stream = wc.OpenRead(fileName))
{
     stream.Read(buffer, 0, 200);
}

but when wc.OpenRead it called it downloads the whole file.


You need to set a Range Header on your WebClient before you invoke the OpenRead method.

See: http://msdn.microsoft.com/en-us/library/system.net.webclient.headers.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消