Im trying to download the file given the above URL, but I do not want
to assume the file is .exe and give it a filename I choose. I want to
use the original name of the file.
Heres a code snippet:
DownloadFile "http://go.microsoft.com/fwlink/?LinkId=42542",
"c:\file.exe"
Sub DownloadFile(URL, myFileName)
Const adTypeBinary = 1
Const adSaveCreateOverwrite = 2
Dim oHTTP, oStream
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
oHTTP.Open "GET", URL, False
oHTTP.Send
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary
oStream.Open
oStream.Write oHTTP.ResponseBody
'###################################################################
' instead of using myFileName, I'd like to use the default name of
the file
' (WindowsInstaller-KB893803-v2-x86.exe in this case)
oStream.Savetofile myFileName, adSaveCreateOverwrite
'###################################################################
oStream.Close
End Sub
Any help would be appreciated. Thx
[snip]
Sorry, nothing below helps.
Unfortunately, the URL's "HEAD" data doesn't contain the filename:
Content-Length: 2585872
Content-Type: application/octet-stream
Last-Modified: Wed, 04 May 2005 22:24:18 GMT
Accept-Ranges: bytes
ETag: "4c43443f850c51:8037"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 06 Dec 2005 20:06:01 GMT
Connection: keep-alive
Both URLs below may download the same file
<URL:http://go.microsoft.com/fwlink/?LinkId=42542>
<URL:http://download.microsoft.com/download/1/4/7/147ded26-931c-4daf-9095-ec
7baf996f46/WindowsInstaller-KB893803-v2-x86.exe>
If the latter were used the filename could be extracted from the URL:
Const cURL = "http://www.microsoft.com/downloads/info.aspx?...
.../WindowsInstaller-KB893803-v2-x86.exe
Dim strFIL
strFIL = Mid(cURL,InStr(cURL,"/")+1)
Microsoft obfuscates the filename via the LinkId.
I could find nothing that would offer any insight.
7baf996f46/WindowsInstaller-KB893803-v2-x86.exe ? If theres a way to
get the URL in this format from the forwarding link (
http://go.microsoft.com/fwlink/?LinkId=42542 ) I could use that just
fine.
A search of
http://www.microsoft.com/
for
WindowsInstaller-KB893803-v2-x86.exe
gave this link
URL:http://www.microsoft.com/downloads/details.aspx?FamilyID=889482fc-5f56-4
a38-b838-de776fd4138c&displaylang=en
which listed the file under
Files in This Download
whose URL was
URL:http://www.microsoft.com/downloads/info.aspx?na=208&p=3&SrcDisplayLang=e
n&SrcCategoryId=&SrcFamilyId=889482fc-5f56-4a38-b838-de776fd4138c&u=http%3a%
2f%2fdownload.microsoft.com%2fdownload%2f1%2f4%2f7%2f147ded26-931c-4daf-9095
-ec7baf996f46%2fWindowsInstaller-KB893803-v2-x86.exe
from which I extracted
URL:http://download.microsoft.com/download/1/4/7/147ded26-931c-4daf-9095-ec7
baf996f46/WindowsInstaller-KB893803-v2-x86.exe
after converting "%3a" to ":" and each "%2f" to "/"