Type Detection Failed - Unsupported URL

My macro has

Dim mArgs(3) as New com.sun.star.beans.PropertyValue

mArgs(0).Name = “ReadOnly”
mArgs(0).Value = False
mArgs(1).Name = “MacroExecutionMode”
mArgs(1).Value = 4
mArgs(2).Name = “AsTemplate”
mArgs(2).Value = False
mArgs(3).Name = “Hidden”
mArgs(3).Value = False

oDoc = StarDesktop.LoadComponentFromUrl(sInitUrl, “MyName”, 0, mArgs())

That last line keeps giving me:

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: Unsupported URL <file:///L:/QMS%20Documents/Working/(QF)%20Management%20Review.odt>: “type detection failed”.

I’ve verified that the URL exists. L: is a mapped drive. The %20’s are spaces. The URL was generated by the FilePicker (“com.sun.star.ui.dialogs.FilePicker”)

Is there a better way to go about this?

May be Dim mArgs(4) as ...,
mArgs(4).Name = "FilterName"
mArgs(4).Value = "writer8" will help?

If you open this file manually, just from the File-Open menu, then there are no problems?

Also try

oDoc = OpenDocument(sInitUrl, mArgs)

I just verified that opening through File>Open works as expected. I guess I had the wrong concept of how the filternames were used. In my case, I had an array filterNames(1) As String, which includes “*.odt” and *.ods", and I feed that array as a parameter to the FilePicker so that it would always allow selection of both writer and calc files. I’ll try your suggestion of including “FilterName”-“writer8” in my mArgs array. Should I also include “FilterName”-“calc8” in that array if I want it to also recognize and open calc files? Also, should I be using “writer8” and “calc8” in my filterNames array for the FilePicker?

Two more questions - why “writer8”? I’m still on LibreOffice version 7-something. Does it have something to do with the version of OpenOffice that LibreOffice is tracking with?

Also, is this filter name propertyvalue just giving the StarDesktop.LoadComponentFromUrl a type to try when detecting the file type?

Please see Listing 5.46:Enumerate all supported filter names.

And read about MediaDescriptor: …If a name is specified on loading, it still will be verified by a filter detection, but in case of doubt it will be preferred

Great, Thanks!
So…it looks like adding one for calc would be self-defeating.

So then, are the filternames fed to the FilePicker completely different?

Yes, because these are different filters: the filter in the FilePicker helps to select files with the desired extension in the folder, the filter in the media descriptor helps to recognize the contents of the file when reading and interpreting it (my English is not good enough to explain in more detail)

Thanks! That’s what I suspected. I just wanted to confirm. By the way, I think your English in the explanation you gave is excellent, and your explanation was detailed enough for me.