How to find out what kind of document is displayed in IE

I am using C # to create a button for IE, and this button does certain actions that depend on the document being the PDF. I'm trying to set up a protector to prevent any action if the document type is not PDF, but I'm not sure how IE renders the Adobe document and the reader is taking responsibility. I am using both SHDocWv after looking at WebBrowserClass objects and not sure how to figure it out. any suggestions?

+1


source to share


3 answers


It's a bit problematic for this AFAIK.

The value of the IWebBrowser2 :: Type property depends on which plugin you have installed that handles PDF files, as some plugins create an HTML wrapper for the PDF file (Adobe for example), so you get "HTML document" as a type and some plugin -ins don't do this (like Foxit), so you can't relay this exclusively.



So, if you got an HTML wrapped PDF document, you can use IHTMLDocument2 :: mimeType to find out the exact document type (JPEG / GIF / PNG / etc. Files that are all wrapped in HTML by the browser). But as I know it is also unreliable, for example on my machine it returns "Firefox Document" for HTML documents because .html files are associated with Firefox: s But I haven't checked if this is the case with als files.

Other parameters are to use the GetUrlCacheEntryInfoEx API call to get the file in the local browser cache that stores the document and then reads it (just the beginning of the file, I think only the first 256 bytes are important) and call FindMimeFromData with the data you just read and it will return the mime type.

+1


source


Check the mime type of the document or look at the window.location.href of the web browser ... If a pdf is displayed you should be able to find it ...



0


source


Another good way is to do the following.

1] Drag the Document object to IPersist and then retrieve the CLSID using .GetClassID (..). 2] pInvoke ProgIDFromCLSID to retrieve the program 3] Match progIDs with known COM objects / applications.

0


source







All Articles