>' Get the byte-order mark, if there is one > loByte = New Byte(lnByteToRead) {} >>
' If this is a PDF If UCase(Mid(lcString, 1, 5)) = "%PDF-" Then cExtension = "PDF" nNoFileType = 2 Clear() Return True End IfOffice files are zip. So, you would need to open that in XML and such:
' If this is a XML If UCase(Mid(lcString, 1, 6)) = "<?XML " Then ' Load the files into the string builder loStringBuilderFile.LoadString(lcString) ' If we have a second line If loStringBuilderFile.nLine > 1 Then ' Get the second line If Not loStringBuilderFile.MLine(2) Then cMessage = cUnableToGetTheSecondLineOfTheXMLFile Clear() Return False End If ' Get the line lcLine = loStringBuilderFile.cLine ' Based on the second line Select Case UCase(lcLine) ' WordML Case UCase("<?mso-application progid=""Word.Document""?>") ' If we can load the Xml loXml.cFile = lcFile If loXml.LoadXmlFromFile() Then ' If we have this attribute at the root loXml.cAttribute = "xmlns: w" If loXml.IsXMLNodeAttributeFromRoot() Then ' If it exists If loXml.lExist Then ' If we can get the attribute from the root loXml.cAttribute = "xmlns:w" If loXml.GetXMLNodeAttributeValueFromRoot() Then ' If this is a WordML file If UCase(loXml.cValue) = UCase("http://schemas.microsoft.com/office/word/2003/wordml") Then cExtension = "DOC" nNoFileType = 21 Clear() Return True End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else ' If we have this attribute at the root loXml.cAttribute = "xmlns:pkg" If loXml.IsXMLNodeAttributeFromRoot() Then ' If it exists If loXml.lExist Then ' If we can get the attribute from the root loXml.cAttribute = "xmlns:pkg" If loXml.GetXMLNodeAttributeValueFromRoot() Then ' If this is a WordML file If UCase(loXml.cValue) = UCase("http://schemas.microsoft.com/office/2006/xmlPackage") Then cExtension = "DOC" nNoFileType = 21 Clear() Return True End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If End If End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If End If ' ExcelML Case UCase("<?mso-application progid=""Excel.Sheet""?>") ' If we can load the Xml loXml.cFile = lcFile If loXml.LoadXmlFromFile() Then ' If we have this attribute at the root loXml.cAttribute = "xmlns" If loXml.IsXMLNodeAttributeFromRoot() Then ' If it exists If loXml.lExist Then ' If we can get the attribute from the root loXml.cAttribute = "xmlns" If loXml.GetXMLNodeAttributeValueFromRoot() Then ' If this is a ExcelML file If UCase(loXml.cValue) = UCase("urn:schemas-microsoft-com:office:spreadsheet") Then cExtension = "XLS" nNoFileType = 22 Clear() Return True End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If Else cMessage = loXml.cMessage ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If End Select End If cExtension = "XML" nNoFileType = 10 Clear() Return True End If ' If this is a Microsoft Office file If Mid(lcString, 1, 8) = Chr(208) + Chr(207) + Chr(17) + Chr(224) + Chr(161) + Chr(177) + Chr(26) + Chr(225) Then ' If this is a Word file If Mid(lcString, 513, 4) = Chr(236) + Chr(165) + Chr(193) + Chr(0) Then cExtension = "DOC" nNoFileType = 1 Clear() Return True End If ' If this is a Excel file If Mid(lcString, 513, 8) = Chr(9) + Chr(8) + Chr(16) + Chr(0) + Chr(0) + Chr(6) + Chr(5) + Chr(0) Or (Mid(lcString, 513, 4) = Chr(253) + Chr(255) + Chr(255) + Chr(255) And Mid(lcString, 518, 1) = Chr(0)) Then cExtension = "XLS" nNoFileType = 3 Clear() Return True End If ' If this is a Powerpoint file If Mid(lcString, 513, 4) = Chr(160) + Chr(70) + Chr(29) + Chr(240) Or Mid(lcString, 513, 8) = Chr(253) + Chr(255) + Chr(255) + Chr(255) + Chr(14) + Chr(0) + Chr(0) + Chr(0) Or Mid(lcString, 513, 8) = Chr(253) + Chr(255) + Chr(255) + Chr(255) + Chr(28) + Chr(0) + Chr(0) + Chr(0) Or Mid(lcString, 513, 8) = Chr(253) + Chr(255) + Chr(255) + Chr(255) + Chr(67) + Chr(0) + Chr(0) + Chr(0) Or Mid(lcString, 513, 4) = Chr(0) + Chr(110) + Chr(30) + Chr(240) Or Mid(lcString, 513, 4) = Chr(15) + Chr(0) + Chr(232) + Chr(3) Then cExtension = "PPT" nNoFileType = 5 Clear() Return True End If cMessage = cUnableToFindTheOfficeDocumentType ' If we cannot get the nNoFileTypeKnownAs based on the extension If Not GetNoFileTypeKnownAsBasedOnExtension() Then End If Clear() Return False End If