Re: File name of a .pdf from IWebbrowser2



Thanks for the replies!

However...

Brian, interesting idea - that would probably work for getting a MIME
type with some spelunking about.

Ismail, normally that would work, but when a .pdf is loaded - there is
no HTMLDocument2 so all of the MIME calls fail. Miserably.

The trick is figuring out how MS gets that file name with IE?

I have a horrible solution that works for now... It falls under the
category:

"You gotta do what you gotta do because of what they done to you"

// if this is an acrobat document it could
// arrive without a valid file suffix and when
// used as the 3rd paramemter in the call
// to URLDownloadToFile() it will cause
// URLDownloadToFile() to fail. first test
// the results of get_Document() with IID_Acrobat
// (which was determined by loading the browser
// control in the VC test ActiveX control container)
// we do a QI on the pDisp returned from get_Document()
// Since we have no idea what this interface looks
// like we store the result in *iAcrobat which is an
// IDispatch*. this is done since we will need to
// call Release() on it - and since the VTABLE is
// the same for all COM objects we can safely call
// Release()

// Acrobat IAcroAXDocShim Interface
// 3B813CE7-7C10-4F84-AD 06-9DF76D97A9AA
DEFINE_GUID(IID_Acrobat, 0x3B813CE7, 0x7C10, 0x4F84, 0xad, 0x06, 0x9d,
0xf7, 0x6d, 0x97, 0xa9, 0xaa);


char *p, documentURL[INTERNET_MAX_URL_LENGTH];
char tempPath[INTERNET_MAX_URL_LENGTH];
char theURL[INTERNET_MAX_URL_LENGTH];
IDispatch *pDisp, *iAcrobat;
HRESULT hr;

// load theURL with iwebbrowser2->get_LocationURL()

hr = iwebbrowser2->get_Document(&pDisp);
hr = pDisp->QueryInterface(IID_Acrobat, (LPVOID *)&iAcrobat);
pDisp->Release();

// if this is a .pdf make sure the file
// terminates in a .pdf suffix

if ((hr == S_OK) && (iAcrobat != NULL)) {
iAcrobat->Release();
strcpy(tempPath, theURL);
strlwr(tempPath);
p = PathFindExtension(tempPath); // find an extension?
if (*p == 0x00) // if there is not one, add one
strcat(p, ".pdf");
else { // if the extension is not .pdf - make it .pdf
if (strcmp(p, ".pdf") != 0)
strcpy(p, ".pdf");'
}
strcpy(documentURL, PathFindFileName(tempPath));
}
else
strcpy(documentURL, PathFindFileName(fixedURL));

.