Seem to be circling back to this but with a different problem.
If the user deletes my suggested filename including the extension the file is saved out as a plain text file with no extension to associate it back to the program.
What am I missing?
Or do you have to validate their entry and add the extension back on? If so at what stage and where do I do that?
I present the SaveAs Dialog
DIM CWPFileTypes as new FileType
CWPFileTypes.Name = “CrosswordPlayerFile”
CWPFileTypes.Extensions = “.cwptext”
dialog = New saveAsDialog
dialog.Filter = CWPFileTypes
dialog.initialDirectory = SpecialFolder.Documents
dialog.PromptText = “Select a location to save your Crossword Player file”
dialog.Title = “Save As”
dialog.SuggestedFileName = “Untitled.cwptext”
dialog.CancelButtonCaption = “Cancel”
dialog.ActionButtonCaption = “Save It!”
Do not modify the filename after the user has provided a location via save dialog.
That’s just poor user experience, and disrespectful to users as well.
Plus, it’d be worth testing if that even works when translocated or sandboxed. Remember you only get access to the location the user has specified. Adding to the filename might hopefully change that. Terrible behaviors like the described are the reason Apple has to keep getting stricter with security.
You can check that the filename isn’t going to be problematic, but DO. NOT. CHANGE. IT.
I had tried Jeff’s approach prior but it doesn’t work.
Just wondering if this is a common problem trying to set the right extension on mac and windows, that is if users delete the extension when saving what happens?
If I set the following it associates the file to the application correctly event though there is no extension attached to the file name but this isn’t an option on windows
savevolfile.MacCreator =
savevolfile.MacType =
Have I created a problem or is it normal behaviour to be able to save files out that are potentially disocciated?
Odd.
This line of code has been working fine for me for the last 5 years:
if right(file.Name.uppercase,4) <> ".PDF" then file.Name = file.name + ".pdf" //oct 2013
I spent years before that providing pointless support to people who angrily emailed to tell me that their saved files could not be found.
I’d rather add the extension and save myself a lot of support time.
To me, helping the user by adding the missing extension when saving is expected behavior.
If there comes a time when Apple clamp down on this, then I’ll stop, or maybe we will get a cross platform SaveDialog that doesn’t enable the save button until the filename is OK
Tim’s Advice DO. NOT. CHANGE. IT.
But if the alternative is ‘tell the user that their suggested filename is not good enough’ ,that also sounds like a poor user experience to me.
I’ll be giving this some thought over the next few days myself.
If I do not write the extension for a filename, I expect the application taking care of that. Adding the necessary extension automaticly by the application will be appreciated by most users, especially those in a hurry.
Here is the code which will add the extension .PDF if the user did not wrote it :
[code]Dim dlgSave As New SaveAsDialog
Dim f_Test As FolderItem
Dim tosFileWrite As TextOutputStream
Dim strTemp As String
dlgSave.InitialDirectory = SpecialFolder.Documents
dlgSave.PromptText = “This is prompt text”
dlgSave.SuggestedFileName = “ThisIsMyFile”
dlgSave.Title = “Example dialog how to save”
f_Test = dlgSave.ShowModal
strTemp = f_test.NativePath
if UpperCase(Right(strTemp, 4)) <> “.PDF” Then strTemp = strTemp + “.PDF”
f_Test = GetFolderItem(strTemp)
tosFileWrite = TextOutputStream.Create(f_Test)
tosFileWrite.Close[/code]
First the program ask for a name. When the user click save then the native path is stored in string variable “strTemp” after which it is checked if it has the necessary extension. After that the file is actually created and saved to disk.
This is only an example and is striped from the necessary tests and processing. What you find after running this code is just a file on the location of your choice.
The file is not actually saved after pressing “Save” in the Save As dialog box. So you can test in the following way what the user choosed :
If f_Test then
// Boolean result of Save As dialog is true, so the user pressed “Save”.
// Do your save actions here
else
// The boolean result of Save As dialog is false, the user pressed “Cancel”
// Do here the cancel actions you want to perform
end if
Also in case the user omitted the extension, you can correct or add it in the “true” region of the “if” block.
I wanted to hilight the fact the user may not know about the extension because by defaule it is not displayed.
And, yes, the extension is visible elsewhere (even when the preference is set to hide the extensions ?).
The other problem users have is they believe that it is enough to change a file extension to change the file contents (replace the avi with mp4 for example). It works, lauch VLC and display the movie, but it does not change the file contents, it just mistake the OS and the Application(s). The data did not changed at all.
As the developer, it is always a good idea to check if the file the application expect has the correct extension. If so, just proceed. If not, your application should try to find out what is wrong. Is it the file it expect, if so, change or add the correct extension. If it is an unexpected file, see if there is a way to retrieve the information or inform the user about the problem.
Xojo is very much capable of artificial intelligence (AI), so implement it in your applications. Your users should be very grafefull for that.