OO-Snippets: Find document Format

Commons

Keywordsdocument format
LanguageOOBasic
ApplicationOffice
AuthorsChristian Junker (initial)
Tom Schindl (initial)
Supported Versions1.1.x  2.0.x  
Supported OSAll  
QuestionHow can I get the document format

Only relying on the operating system which it self relys ont the file suffix

is sometimes not enough

Answer

You could use deep type-detection

Code-Snippet-Listing (snippet-source)

Sub detectDocType() 
    Dim mediaDescr(30) as new com.sun.star.beans.PropertyValue 

    docurl = thisComponent.getURL() 
    mediaDescr(0).Name = "URL" 
    mediaDescr(0).Value = docurl 

    typemgr = createUnoService("com.sun.star.document.TypeDetection") 
    'make deep type detection (not just based on filename extension)
    msgbox typemgr.queryTypeByDescriptor(mediaDescr(), True) 

End Sub

Changelog

DateUserModification
2005-09-13cjInitial version

and