Solved

Determining the length of a file with WinInet

Posted on 2002-04-24
7
669 Views
Last Modified: 2010-04-04
Hi,

I am using this code with the asynchronous WinInet to determine the length of a file...

dwBufferLen:=SizeOf(pr.dwTotalLength);
dwIndex:=0;
if (HttpQueryInfo(pr.hOpenURL, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER, @pr.dwTotalLength, dwBufferLen, dwIndex) = FALSE) then pr.dwTotalLength:=0;

This is done so that I can display a progress bar whilst the file is downloading.  For many sites this works fine, however for some sites I find that it always returns zero.  For example...

www.google.com
www.yahoo.com
www.ask.com

As a result I can't display a progress bar for some sites when the download takes place because I am unable to determine the length of the file before the download starts, so it isn't possible to know how much progress has been made.

I guess it doesn't work with some sites because the length information isn't stored in the HTTP header??  Do you know of any way around this problem?

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:Alone
ID: 6965658
But server does support downloading resume?

WBR...
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 6965790

Richard,

It is possible that the servers on these sites do not generate the "Content-Length:" header item. This is not a required header, though most sites do return it. If I remember correctly, this is the header used to return the results for the HTTP_QUERY_CONTENT_LENGTH flag. Other than that, I'm not sure why it would fail.
Have you checked GetLastError() in the cases where it does fail? This may help give you/us a little more info to go on.

Russell
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 6965914

Richard,

Did some more research into this (MSDN and other sources). In cases where you are not able to get the resource size, there is not much your going to be able to do in regards to displaying upload/download progress. One possible work around to this is to modify your progress to be timed based, as well as progress based. For the resources where you are not able to get size, you could then update the meter based on timed increments, giving the user the appearance of progress. Hope this helps.

Russell


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6967317
monitoring..
haha .. didn't use 'listening' :)
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6967447
Can you inspect the TCP/IP packet information?
When transfering files, the individual packets are numbered and (I think) include the total number of packets being sent.

Will any other transfer protocol, such as FTP, provide size or transfer progress data?
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6967746
interested ;P
0
 

Author Comment

by:Richard2000
ID: 6968148
Hi Russell and all,

Thank you for your comments and for looking into this for me.  I thought that the problem was caused by the length information not being present because it works fine on most sites, but fails on some sites.

So this is what I've chosen to do.  For sites where the length information isn't present, I estimate the length and use that for the progress bar.  Since it is mainly web pages that I am downloading, I use 20K as the length and make that go up to 80% on the progress bar and no further.  Then when the download has finally completed I set this to 100%.  Of course, this isn't 100% accurate but it is better than having a blank progress bar and it is hardly noticable.  It is also easy to code.

Richard
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question