As part of my Flex application users can save their work to a text file on their local machine. They can then later load these files.
Both loading and saving use a FileReference object, and bounce the files off the server as needed.
It all works pretty well, but the problem is that if the user decides to overwrite the filename there is the very real possibility that they will forget to add the extension.
For example, the default name comes up as "untitled 1.txt", and they just type "myfile".
The result is that when they then go to load the file it does not appear - because I am filtering for just ".txt" files.
It's pretty normal in a Windows application to automatically append a default extension, but I can see no equivalent in Flex.
Is this something that can be done?
If not are there any good workarounds?
I don't think there's any way to automatically add an extension. You could access the name and type of the file after the browse() method has completed and store it with the user's account on the server or locally in a shared object. A user could also choose to store the file at a different path and there's no way to access that information.
It's disappointing that it doesn't have the option to add an extension. I can possibly understand if it disallowed ".exe" as a default, but apart from that I can see no good reason for this omission.
In the end I just added a SELECT listener, where I check the saved name, and if the extension is missing I warn the user that they should go and rename the file.
It's a bit clumsy in my opinion, but because the SELECT event comes AFTER the file has been saved, there's no way to cancel the download, so a warning seems like the best that can be done.