Wanted to utilize explorers "New" submenu in an application for both XP and Vista - read this then

Microsoft changed the way to create new files from XP to Vista and the support for this in .NET on Vista vs. XP is rather poor. It took some research to figure how to find the correct files.

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:
  1. 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.
  2. 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.
  3. 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 ;)
  4. 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.
On WinXP you could use following method in .NET to find the folder where the templates are located:

string templateFolder = Environment.GetFolderPath(Environment.SpecialFolder.Templates)

In WinXP you get the following directory as a result: "C:\Documents and Settings\Templates". Here are all the templates stored. All you had to do was to copy the templates into the desired location and you were good to go.

In Vista you get the following directory: "C:\users\AppData\Roaming\Microsoft\Windows\Templates". The directory exists, but there's no content in it. Bummer! After some research I found this blogpost which lead to success. Looking into "C:\Windows\ShellNew" gives me template files for all Office documents and OpenOffice documents. Finally a directory where I actually find templates!!!