Search code examples
.netvb.netexcelinternet-explorermicrosoft.mshtml

mshtml.IHTMLElement getAttribute erratic behaviour


In an application, I am using mshtml.IHTMLElement.getAttribute(mimetype) to extract the mimetype within a mshtml.HTMLDocument.

Example:

www.mywebsite.com/index.html. 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 ("NONE FOUND")

   Else
       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 MsgBox displaying MIMETYPE My colleague is running this application sitting in location-2 (Asia), when he accesses that webpage, he gets a pop-up MsgBox displaying NONE FOUND. 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 MIMETYPE based on geo-locations. He can access the Excel workbook by manually going into browser and clicking on the link.


Solution

  • 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.