Is it possible to upload only one part of a file (for example, the first 100 KB) in C #?

I'm just wondering if this is possible - I know how to upload a file, but how can I upload only the first 100 Kbytes of a file?

+3
source share
1 answer

Try the following:

        string GetWebPageContent(string url)
        {
            string result = string.Empty;
            HttpWebRequest request;
            const int bytesToGet = 1000;
            request = WebRequest.Create(url) as HttpWebRequest;

//get first 1000 bytes
            request.AddRange(0, bytesToGet - 1);

// the following code is alternative, you may implement the function after your needs
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                }
            }
            return result;
        }

Stolen from here .

+8
source

Source: https://habr.com/ru/post/1758793/


All Articles