FolderItem.launch does not launch

My code:
s = List1.CellTag(List1.ListIndex, 1) ’ valid path to a MS word file
f = GetFolderItem(s,FolderItem.PathTypeAbsolute)
If f <> Nil Then
MsgBox(“Attempting launch”) ’ this does appear
f.Launch
End If

Nothing gets launched. The forum entries don’t seem to be very helpful about this. Is there a solution?

The issue is your path / reconstruction combo. The message box not appearing is an indication that your FolderItem isn’t getting constructed. To see for yourself, take f.Launch outside of the if statement, and a NilObjectException will happen.

Please do not use absolute path - it is deprecated (and in my personal opinion should be removed now)
http://documentation.xojo.com/index.php/FolderItem.AbsolutePath

You can store objects in CellTags, so I would recommend storing the actual FolderItem from the user. If that is not an option, be sure that your saved path is correct, stored as a NativePath, and restored using the FolderItem constructor.

It is best not to mess with paths, and reconstructing FolderItem with them. Use FolderItem.GetSaveInfo if you need to save and load a FolderItem.

My general rule of thumb is: If you’re contemplating GetFolderItem, don’t.
Paths and FolderItem gets tricky, and if there’s a way to not deal with it take that route.

and check the file exists

s = List1.CellTag(List1.ListIndex, 1) ' valid path to a MS word file f = GetFolderItem(s,FolderItem.PathTypeNative) If f <> Nil And f.Exists Then MsgBox("Attempting launch") ' this does appear f.Launch End If

Apparently the file does exist, because after inserting 'And f.Exists ’ I still get the message.
re: Tim Parnell’s reply:
I have changed all the “Absolute” strings to “Native” (it has been a while since I looked at this program) and it makes no difference.
I am storing the NativePaths in the CellTag, rather than the whole FolderItems, because there are a lot of them and I’m old-fashioned enough not to want to waste that much memory.
So … is Launch supposed to work?

if you have

f as folderitem

and set you set f to be a file

and

f.exists = true

Then setting the celltag to the folderitem uses a bit more memory than a string, but isnt the whole file and isnt a major memory overhead.

So set the Celltag to the folderitem

celltag(whatever)  = f

Then later

f = celltag(whatever) f.launch
will work fine.

[quote=352655:@Roland Foster]Apparently the file does exist, because after inserting 'And f.Exists ’ I still get the message.
re: Tim Parnell’s reply:
I have changed all the “Absolute” strings to “Native” (it has been a while since I looked at this program) and it makes no difference.
I am storing the NativePaths in the CellTag, rather than the whole FolderItems, because there are a lot of them and I’m old-fashioned enough not to want to waste that much memory.
[/quote]
A long enough absolute path may use more memory than a folderitem

[quote=352655:@Roland Foster]
So … is Launch supposed to work?[/quote]

If Word is installed it should open it Word - without Word quite possibly not as there may be no application set to open that kind of file

I’m sorry, I misread the comment in your original post. If that message box is being displayed, then there’s an issue with something else. I would try to launch something else, perhaps a .txt file to see if Excel is being finicky.

What OS are you using?
LaunchServices may be confused.

Side note: Switching to NativePath when the paths are stored as AbsolutePath won’t automagically fix anything. I’m just trying to encourage you to use NativePath moving forward. You would need to work around any already stored AbsolutePath strings.

Could you post the actual path ?

The essential parts code to get and store the file paths are as follows:
Dim dlg As New SelectFolderDialog
g = dlg.ShowModal
If g = Nil Then
Quit
End If
For i = 1 to g.Count
f = g.Item(i)

List1.CellTag(List1.LastIndex, 1) = f.NativePath
Next

I select a row of the listbox, then click a button to open the file.
This is now the code called by the button’s click event

Dim f As FolderItem
Dim s As String
s = List1.CellTag(List1.ListIndex, 1)
MsgBox("file path is " + s)
f = New FolderItem(s)
If f <> Nil And f.Exists Then
MsgBox(“Attempting launch”)
f.Launch
End If

The MsgBox statements output:
file path is D:]GNGnew\Good_Docs\201301 Balm in Gilead.doc

Double-clicking on the same file in File Explorer opens it in Microsoft Word 2007.

I’m running Windows 10 64-bit
The program is being test-compiled and run in Xojo 2017r2.1

Yeah, just store the FolderItem, no need to jump through so many hoops.
Have you determined if FolderItem.Launch on a text file works appropriately?

My test project / example for you is working perfectly.
Take a look: file_launcher.xojo_binary_project

Interesting - files with extensions of .rtf and .docx do launch into Word.
But .doc files launch from File Explorer.
I’ll have to finagle a bit to try .txt

.txt file launches correctly into NotePad.

D:]GNGnew\Good_Docs\201301 Balm in Gilead.doc

is that ] a typo in the forum? or in your code??

Sorry, it’s a typo in my forum reply. Of course it should read
D:\GNGnew\Good_Docs\201301 Balm in Gilead.doc
I guess my problem is probably with Windows, but I’m glad I asked
because I learned some things. It is good to get back to doing some
Xojo code after a lengthy absence.

Check if Word has all its default in the defaults control panel. .doc should indeed open in Windows, or if not windows, WordPad. Something is not right on your system.

Simple to check.

dim f as folderitem f = getopenfolderitem() f.launch

what happens?

dim f as folderitem
f = getopenfolderitem("")
f.launch

Same result - does not launch.

Michael -
Of course I checked file associations. .doc files are supposed to open in Word by default, and, as I said earlier, they open correctly in Word when “launched” from File Explorer.
I’ll be upgrading my Office code soon - maybe that will make a difference.

maybe the space in the file name of doc file?? try remove the spaces and try again.