SaveAs Dialog not adding extension

I’m using SaveAsDialog to set up a file defined in MyFileTypes window, it does not set the extension as specified in the file type.

A simple test program below works fine. The code section in the real program is identical.

Under what circumstances will the extension not get set in the folderItem?

I’m using Classic code under Xojo (2018 Release 1) on an iMac running HighSierra

Dim f As FolderItem
Dim stream As TextOutputStream

dim dialog as new SaveAsDialog
dialog.filter = FileTypes1.AccountAcnt
dialog.SuggestedFileName = “DailyPlant Staff”
dialog.initialDirectory = SpecialFolder.Documents
dialog.PromptText = “Enter a FileName”
dialog.Title = “Making a copy”

f = dialog.ShowModal()

If f <> Nil then
msgbox f.name
stream = TextOutputStream.Create(f)
f.MacCreator = “Acnt”
Stream.WriteLine(“Perry White”)
Stream.WriteLine(“Lois Lane”)
Stream.WriteLine(“Jimmy Olsen”)
Stream.WriteLine("<<< The End >>>>")
Stream.Close
End If

It ‘doesnt happen automatically’ enough times ,that eventually I took to checking the name afterwards and adding the extension myself before saving if it was missing.

msgbox f.name //our extension is GDS if uppercase(right(f.name,4)) <> ".GDS" then f.name = f.name + ".GDS" stream = TextOutputStream.Create(f)

The following may not be relevant but just in case:

In Windows, you should be aware that even if the extension exists, most systems are setup to NOT SHOW the extension for a registered file type when viewing using Explorer.

Ironically, that appears to have been to make Windows ‘work like a Mac’
Macs used to use mac creators and file types to allow a file of any name (with or without extension) , to be opened by the proper app, and so tended not to bother with extensions.
Windows hid extensions by default to make it look like the same thing was happening.
Then Macs allowed ‘open based on file extension’, and seem to have gradually embraced that , making it more like Windows.
Now we come full circle because if you go to Advanced Preferences on a Mac, you can select ‘Show all filename extensions’ or not.

I feel Apple had an influx of former Windows programmers who mucked MacOS X up. Just look at iTunes …

After reading some old code that wasn’t directly relevant to the problem in question, I came to a similar idea and found that adding a check and modifying the name was a workable work-around. Sounds like it is more than that - it is the only way to get it to work reliably.

Thanks for your replies - I’ll not pursue this case any more.

[quote=389392:@Robin Harrington]I’m using SaveAsDialog to set up a file defined in MyFileTypes window, it does not set the extension as specified in the file type.

A simple test program below works fine. The code section in the real program is identical.

Under what circumstances will the extension not get set in the folderItem?

I’m using Classic code under Xojo (2018 Release 1) on an iMac running HighSierra

Dim f As FolderItem
Dim stream As TextOutputStream

dim dialog as new SaveAsDialog
dialog.filter = FileTypes1.AccountAcnt
dialog.SuggestedFileName = “DailyPlant Staff”
dialog.initialDirectory = SpecialFolder.Documents
dialog.PromptText = “Enter a FileName”
dialog.Title = “Making a copy”

f = dialog.ShowModal()

If f <> Nil then
msgbox f.name
stream = TextOutputStream.Create(f)
f.MacCreator = “Acnt”
Stream.WriteLine(“Perry White”)
Stream.WriteLine(“Lois Lane”)
Stream.WriteLine(“Jimmy Olsen”)
Stream.WriteLine("<<< The End >>>>")
Stream.Close
End If[/quote]
Check the ExtensionVisible property. It may be that the user has that turned off.

http://documentation.xojo.com/index.php/FolderItem.ExtensionVisible