Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 763475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:34:00+00:00 2026-05-14T16:34:00+00:00

I would like to use the WebClient (or there is another better option?) but

  • 0

I would like to use the WebClient (or there is another better option?) but there is a problem. I understand that opening up the stream takes some time and this can not be avoided. However, reading it takes a strangely much more amount of time compared to read it entirely immediately.

Is there a best way to do this? I mean two ways, to string and to file. Progress is my own delegate and it’s working good.


FIFTH UPDATE:

Finally, I managed to do it. In the meantime I checked out some solutions what made me realize that the problem lies elsewhere.

I’ve tested custom WebResponse and WebRequest objects, library libCURL.NET and even Sockets.

The difference in time was gzip compression. Compressed stream lenght was simply half the normal stream lenght and thus download time was less than 3 seconds with the browser.

I put some code if someone will want to know how i solved this: (some headers are not needed)

public static string DownloadString(string URL)
    {
        WebClient client = new WebClient();
        client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5";
        client.Headers["Accept"] = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
        client.Headers["Accept-Encoding"] = "gzip,deflate,sdch";
        client.Headers["Accept-Charset"] = "ISO-8859-2,utf-8;q=0.7,*;q=0.3";

        Stream inputStream = client.OpenRead(new Uri(URL));
        MemoryStream memoryStream = new MemoryStream();
        const int size = 32 * 4096;
        byte[] buffer = new byte[size];

        if (client.ResponseHeaders["Content-Encoding"] == "gzip")
        {
            inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
        }

        int count = 0;
        do
        {
            count = inputStream.Read(buffer, 0, size);
            if (count > 0)
            {
                memoryStream.Write(buffer, 0, count);
            }
        }
        while (count > 0); 

        string result = Encoding.Default.GetString(memoryStream.ToArray());
        memoryStream.Close();
        inputStream.Close();
        return result;
    }

I think that asyncro functions will be almost the same. But i will simply use another thread to fire this function. I dont need percise progress indication.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:34:01+00:00Added an answer on May 14, 2026 at 4:34 pm

    You only get the last iSize bytes from your file since you overwrite your buffer on each iteration, you’re not saving the buffer anywhere. Here’s a sample on how to store the file in memory using a MemoryStream.

    var totalBytes = new MemoryStream(1024 * 1024);
    while ((iByteSize = streamRemote.Read(byteBuffer, 0, iByteSize)) > 0)
    {
        totalBytes.Write(byteBuffer, 0, iByteSize);
        iRunningByteTotal += iByteSize;
    
        //Some progress calculation
        if (Progress != null) Progress(iProgressPercentage);
    }
    

    When the whole download is complete, then you can convert it into text.

    var byteArray = totalBytes.GetBuffer();
    var numberOfBytes = totalBytes.Length;
    var text = Encoding.Default.GetString(byteArray, 0, numberOfBytes);
    

    Update: the DownloadStringAsync method basically does the same as above, but will not give you any progress indication. There are some other async methods though which will fire the DownloadProgressChanged event.

    Update 2: Regarding response time. Have you timed download of the resource using some other tool? Major browsers have builtin support for timing such tings.

    Further, is it a static file your serving up or is the content generated on the serverside?

    A third thing that comes to mind is serverside buffering. E.g. if the Response.Buffer property in ASP.Net is used, nothing will be sent to the client until the whole file/page is done serverside. Thus the client will have to wait before it can start downloading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use a component that exposes the datasource property, but instead
In an asp.net application, I would like to combine the use of the Webclient
I would like to use a language that I am familiar with - Java,
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use VB9 but am not sure what syntax to use
I would like to use something like CLR Profiles on .Net 2.0 to see
I would like to use as and is as members of an enumeration. I
I would like to use client-side Javascript to perform a DNS lookup (hostname to
I would like to use javascript to develop general-purpose GUI applications. Initially these are
I would like to use my laptop as a web development (PHP, Python, etc.)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.