Solved

Downloading Internet Files

Posted on 1998-01-23
1
626 Views
Last Modified: 2013-11-20
I am working on an application to download a file from the Internet. I can do this successfully via the http functions but I'd like to put the retrieved file into cache. Does anyone know how to use the URLDownloadToCacheFile() function? Is this the right one? Do I have to be connected to the Internet first before I use it? What gives this command an Internet context? Any sample code anywhere?
0
Comment
Question by:rhans042197
[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
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1314638
Yes, the URLDownloadToCacheFile() function is the right one. The latest Internet Client SDK has more information about the 4th parameter.

dwBufLength
DWORD value that contains the size of the szFileName buffer or a flag. If a flag is set to dwBufLength, the buffer is assumed to be of size MAX_PATH. The flag can be one of the following values:
URLOSTRM_USECACHEDCOPY_ONLY  Only download the resource from the cache.  
URLOSTRM_USECACHEDCOPY  Download the resource from the cache if it is available; otherwise, download it from the Internet.  
URLOSTRM_GETNEWESTVERSION  Download the resource from the Internet, if it is newer, and store it in the cache.  

A simple example:

TCHAR pszFilename[MAX_PATH];

HRESULT hr = ::URLDownloadToCacheFile(NULL,  // for non ActiveX component
                                      _T("http://www.somewhere.com/somefile.dat"),
                                      pszFilename,
                                      URLOSTRM_USECACHEDCOPY,
                                      0,
                                      NULL);

if (SUCCEEDED(hr))
{
    // the file has been successfully downloaded, pszFilename contains the cached file name
}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

622 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