Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Saving files to the Windows desktop
Many applications produce output in the form of a disk file. This may be a simple text file listing an audit trail; a Word document as a personalised letter; or an Excel spreadsheet as an alternative to a printed report.
If these files need to be kept for any length of time or if there are many different types of file then they are best kept in a structure of separate folders. If however the files are produced rarely and will be be printed or despatched immediately then the desktop may be the best place to put them.
This sounds like an unstructured way of working but it does have a number of advantages - especially for unskilled or occasional users:
- The files are obviously 'there' and the user will know that the application has produced the output.
- The user can't lose the files or forget the path to the folder.
- Files won't accumulate because the user can see the old files and will be able to delete them
Where is the desktop?
The desktop is nothing more than a folder. It has different names in different versions of Windows and there may be several different copies of it, one for each user. On this machine my desktop is stored as:
You may be tempted to build this string for yourself but there is no guarantee that the desktop folder will always have a path of this form. A safer method is to ask Windows for the path.
Finding the desktop
Use the Windows Scripting Host(WSH) to get this information. The SpecialFolders method will return the path:
lcDesktop = loShell.SpecialFolders('desktop')
Once you have the path you can very easily write your file to this folder with the STRTOFILE command:
StrToFile ('Test', lcDeskTop + '\' + lcFileName)
MessageBox (lcFilename + ' saved to Desktop.')
The MessageBox is just there to reassure the user because the new file may be hidden on the desktop behind the application that's running.