I’m using progressbar in c# but I got a bit of a problem I’m connecting to a server in our company and then I start to download an XML file from that 4k by 4k and showing this progress on a progressbar and for showing this if the file is below 100K till now then the maximum size of my progressbar would be 100 and if it changes I would change the maximum size of it to 1000 then 10000 and etc, so by this way I can doing this
progressbar1.value += 4;
So it’s somehow working, but as all you know the right solution is to know the size of the file my connection is going to download before starting to download that. I think a little and I think using Curl maybe solve the problem, but I don’t know exactly how to use it in C# or is there anyway to solve this problem.
Edit:
I’m downloading the file like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = new NetworkCredential(usr, pass);
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader s = new StreamReader(response.GetResponseStream());
int i = 0;
int j = 0;
int lastIndex = 0;
int readNum = 0;
Console.WriteLine("start at : " + DateTime.Now);
while (!s.EndOfStream)
{
readNum = s.ReadBlock(temp, 0, 4096);
if (w != null)
w.incByVolume(4);
ret += new String(temp);
temp = new char[4096];
}
Thanks in advance…
If you load it with HTTP(S) you can use
WebClient.DownloadFileAsyncwhich has all you need:If you need credentials to acces the page, you can use the
Credentialsproperty of the WebClient.According to the notes on
WebClient:So it would even work with loading the file from a share using the
file:identifier.