How to replicate the default download process in Internet Explorer?

Hey there,

I would like to know how I can call the default download function of IExplorer.

I implemented a custom download manager using the IDownloadManager interface because I needed to get some specific information about the file being downloaded. However, I don't want to override the whole download process. I just needed to intercept it, get the necessary information and let it carry on with the default process.

Currently IExplorer is calling my IDownloadManager::Download() function everytime use clicks Save in IExplorer. Can anyone show me how to call the default process, or to replicate it Which means, open the save as dialog, download it and show the current progress dialog if necessary.

Thanks a lot!!!



Answer this question

How to replicate the default download process in Internet Explorer?

  • Nubby

    Yup, many ways. It would be great if you can dig it out. I can give you my email if you're not too busy. Thanks for the many pointers.


  • Walter30140

    Hi

    It only takes one parameter lpzFilename = url of the file to be downloaded

    It opens the IE file download dialog and prompts the user to save or open the file. Its as close as to the default download process in Internet Explorer as you can get. If you want to change the default folder for downloads you will find that in the registry under the users Internet Settings (I think Download Folder). I saw one article a long time ago about tweaking the UI for this library (just like you can tweak the UI's of the Common control libraries) but I cannot give you a direct link.

    If your intending to build some sort of software update mechanism, look to use the Wininet.dll library. There are a few cheap download ActiveX controls that you can include in your software. I am using Advanced LiveUpdate ActiveX Control ($30US). You may like to search msdn for info about windows update... I am not sure, but there may be a sdk.

    Regards.



  • ThirtySix Software

    Hi,

    That you get the security alert indicates that its working!

    Is there something different about the file you are trying to download Its extension/file type/mime type Check if you have the file type registered in file types in Windows Explorer Tools>Folder Option - File types tab, and that you have checked "Confirm open after download" on the Advanced options.

    There is also a setting in IE (somewhere, can't remember off the top of my head, maybe the Advanced tab) that checks to see if the file extension matches the internal content. The first couple of bytes of all files usually has the file extension/type of the file, so if you have renamed your file extension to something different from its content this may be the cause.

    There is an internal listing of "Unsafe File types" maintained by IE that prevents the download of certain file types... The beta versions of IE7 had a settings option to switch this off, but its been omitted in the PRC version. I have a utility to override these restrictions written in VB6. Post back if you reqire to give it a try. I am in the process of converting my apps to the .net framework, so I can probably provide you the .net version.

    I presume that since you are using C#, your target platforms are Win XP and Vista. I am still in the stone age and not up to speed with Vista... perhaps protected mode settings may have a bearing.

    Regards.



  • TestEng

    Hey Rob,

    Thanks for the reply. A quick search on DoFileDownload didn't reveal much information as to how to use it. I'm also using .NET C# so I wasn't able to find a lot of useful information, but I'll keep on looking.

    Do you know of any good place to look at for some C# examples Or if it's not too much trouble, can you give a quick basic demonstration

    Once again, thanks a lot!!


  • KentaroM

    My guess is that there is something about the Apache server at wiki that may be different from the norm... maybe steaming files from a database i/o from the file system.... maybe different encodings, like you said.. you get a bit that is being interpreted as an eof character.... maybe they have not configured their server... buffer size, to only allow downloads of small files (web page requests)

    You may like to get yourself the fiddler tool ... http://fiddlertool.com and check out your request and response headers when the download initiates and when it completes



  • JimMcCaw

    Hey,

    Thanks for the tip about Fiddler, it works great. Seems like the file url on our wiki is being redirected. Perhaps WebClient.DownloadFile() does not auto follow redirections well. The file I ended up getting is too small to be correct. So I changed its extension to .html and sure enough it's a webpage. It downloaded a page instead of following the redirected link to the file. I'll do some more digging on this problem in the next few days unless you know exactly what's wrong.

    Taking a step back in all of these issues. I wonder if I am even taking the right approach. My original goal is only to find a way to track file download events from Internet Explorer. Everytime there's a download, I need to retrieve 2 things: the source URL and the destination path saved. The FileDownload() event handler didn't give me the necessary info and after a few trials and errors, my current path is making a custom download manager. But now that I think about it, writing a custom download process just to retrieve those info seem unnecessary. There has to be an easier solution to track these paths.

    Please let me know if there is a better approach to easily track the download and saved URLs of a file in IExplorer.


  • white2grey

    Hi, Its not my code, somewhere on my 120 Gb drive I have a sample I downloaded a long time ago. It would take me forever to dig it out of that monster. I am just quoting from memory. As you have discovered there are always a number of ways of doing the same thing when writing code.

    Regards.



  • Anmol Ranka

    Hey Rob,

    I get the security warning every time I try downloading, even a simple Word document =/. I doubt it has anything to do with explorer security, most likely improper hooking of IExplorer on my end.

    I've actually resulted to replicating the whole download process by writing my own progress dialog and using WebClient.DownloadFile() to download. But I am also experiencing some problems using this particular method to download. The download works fine for most files but all of the files downloaded from our wiki page are corrupted. It only got 6 KB of a 10.8 MB zip file. When stepping through the process, the only difference I could tell is our wiki page has a different codepage (65001).

    Anyways, I'll crank it out a little more on the DoFileDownload() api to see if I can narrow down what's wrong. If you don't mind showing your code, it would be great if I can see your example when you have it converted. Please don't feel forced to show if you don't want to =).

    Lastly, thanks a lot for all your responses, they were very helpful!!!



  • arsonist

    Hey Rob,

    I am giving the DoFileDownload() api a try. I've used a Win32 wrapper to convert to C#, which looks something like this:

    public static Int32 DoFileDownload(string lpszFile);

    I followed your instructions and made the call to DoFileDownload() from my download manager. I stepped through the process and verified that the url passing in is correct. However, I ran into a security alert dialog when the code enter the DoFileDownload() function, "Your current security settings do not allow this file to be downloaded."

    I searched arround and checked that all my security settings are correct and should allow for the download. Do you have any idea what's prompting the security alert Did I miss something when trying to implement this api Thanks!



  • Stephen_Sbh

    I am writing a client software for windows, which learns from past user actions. So I need to track a few things user does, including downloading files. I would need to know from where, and to where. So I've implemented the IDownloadManager interface to handle the download process.

    My download works for most links but not for others. When I click on a download link on our wiki page, instead of the 10 MB zip file I expected to get, I get a 6 kB zip file. Turns out the zip file my code downloaded is a html page, specifically a login page. I used to think it was a redirection issue, but now I believe it's more of a security issue and I'm not passing the correct credentials. Maybe, my code must somehow find the login info that I prev logged in with and feed it to the appropriate place before I can get directed to the real file location. PLEASE HELP IF YOU HAVE ANY INSIGHTS!!

    Here are a few important info retrieved when I stepped through the code with the debugger, I was trying to download a 10 Mb zip file:

    HttpWebRequest object properties
    Address = {http://....{hostname}.../confluence/download/attachments/12456/File.zip}
    ClientCertificates = {System.Security.Cryptography.X509Certificates.X509CertificateCollection}
    Proxy = {System.Net.WebRequest.WebProxyWrapper}
    RequestUri = {http://...{hostname}.../confluence/download/attachments/12456/File.zip}

    HttpWebResponse object properties obtained from (HttpWebResponse)webRequest.GetResponse():
    ContentLength = 6488 <--- (first clue that something went wrong)
    ContentType = "text/html;charset=UTF-8"
    Cookies = {System.Net.CookieCollection}
    Headers = {Pragma: no-cache
    Connection: close
    Content-Length: 6488
    Cache-Control: no-cache, no-store, must-revalidate
    Content-Type: text/html;charset=UTF-8
    Date: Thu, 22 Feb 2007 03:33:27 GMT
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Server: Apache/2.0.52 (Red Hat)}
    ResponseUri = {http://...{hostname}.../confluence/login.action;jsessionid=A68FA707 os_destination=/download/attachments/12456/File.zip}
    ResponseUri.AbsoluteUri = "http://...{hostname}.../confluence/login.action;jsessionid=A68FA707 os_destination=%2Fdownload%2Fattachments%2F12456%2FFile.zip"

  • GunaChinna

    There's no good way to get the path-saved information out of Internet Explorer without writing your own downloader. Can you elaborate on what you'd use this for
  • R.S.N

    Hi,

    IE uses the DoFileDownload api from shdocvw.dll. Just call it from your download manager.

    vb declaration

    Declare Function DoFileDownload Lib "shdocvw.dll"(byval lpszFile as string)as long

    Regards.



  • c&amp;#35; interface

    Hey there, I was able to track down DoFileDownload() although it was undocumented by MSDN. However, DoFileDownload() only allow for predefined source URL. I have both source URL and destination path selected so I want to bypass the SaveFileDialog showed by DoFileDownload().

    Is there a way to do that What exactly does DoFileDownloadEx() do and does anyone know the paramenters for this function


  • How to replicate the default download process in Internet Explorer?