In Windows Explorer a user can right-click, choose new and then the user gets presented with a list of different files to create. We have an application which needs to have this functionality available to the user. Windows stores information on how to create these files in the registry. Under a ShellNew key there are some options set up. You can read more about this in this book.
Basically there are four different ways to create a new file:
- NullFile
This means that you can create a new file without worrying about the content in the file. A good example is a .txt file. You just create a new file with the correct extension and you are good to go. - Data
This means you create a new file, but you have to flush some special content into the file which is stored in the registry. A good example is using .rtf where there are som special data in the beginning of the file. - Command
Have not tried this one since there isn't a requirement to support this kind of file. Windows have "Briefcase" as a command. Do you need it - you're on your own ;) - FileName
In this scenario you get a filename from the registry which acts as a template. You then have to make a copy of the template to a new file with the filename you want. Here's were all the fun begins.
string templateFolder = Environment.GetFolderPath(Environment.SpecialFolder.Templates)
In WinXP you get the following directory as a result: "C:\Documents and Settings\
In Vista you get the following directory: "C:\users\
No comments:
Post a Comment