user2979010 user2979010 - 1 year ago 98 Question

mshtml.IHTMLElement getAttribute erratic behaviour

In an application, I am using

to extract the mimetype within a

Example: This webpage has 1 mimetype, and it is an Excel workbook.

Dim oHTML_Element As mshtml.IHTMLElement
Dim HTMLDoc As mshtml.HTMLDocument

HTMLDoc = CType(oBrowser.Document, mshtml.HTMLDocument)
'//mimtype = "Microsoft Office Excel 97-2003 Worksheet"

For Each oHTML_Element In HTMLDoc.getElementsByTagName("a")
If oHTML_Element.getAttribute("mimetype") is Nothing then

MsgBox( oHTML_Element.getAttribute("mimetype").ToString())

End If
End For

The problem:
I am running this application sitting in location-1 (Asia Pacific), when I access that webpage, I get a pop-up

My colleague is running this application sitting in location-2 (Asia), when he accesses that webpage, he gets a pop-up
Webpage access is not the problem and we are accessing the webpage around the same time and its a static page , in other words it does not serve
based on geo-locations. He can access the Excel workbook by manually going into browser and clicking on the link.

Answer Source

Ok! I think I finally figured it out!

The culprit here is the mimeType. On my machine, I have MS Office 2010 installed whereas on my friend's machine he has Office 365.

Inside my C# code, I was searching for mimeType = "Microsoft Office Excel 97-2003 Worksheet" within mshtml.HTMLDocument and it worked fine. Now, searching for the same mimeType on the webpage rendered on my friend's machine yielded None. The problem was that XLS gets a mimeType = "Microsoft Excel 97-2003 Worksheet" when a machine has Office 365 and mimeType = "Microsoft Office Excel 97-2003 Worksheet" for older versions of Office.