views:

671

answers:

1

What's the simplest way to associate my application with a file-extension that works for both Vista and previous versions of Windows ?

Does anyone have an example ?

+1  A: 

This answer won't work for everyone - but if you are deploying a ClickOnce application (it's worth considering, at least) then you can set file-associations in Visual Studio for your app.

In the ClickOnce application Properties (this is for VS 2008):

  • Publish tab
  • Install Mode and Settings --> The application is available offline as well
  • Options... button
  • Publish Options --> File Assocations
  • Set up the Extension|Description|ProgID|Icon that you wish to trigger your app

I tried it with this 'beta' app DeepZoomViewer (ClickOnce published) - the file associations (in this case .DZI and .DZC) definitely work on both XP and Vista.

Even better, when you uninstall the ClickOnce app, the file associations it created are removed for you (again, my test app uses .DZI and .DZC). No registry hacking required.

EDIT: another link describing manually adding the file associations.

CraigD
From the MSDN site :"To Set the ClickOnce Deployment Properties You must have a completed Windows Application that uses Crystal Reports"This is going a bit too far for me - just because I want to assiociate a file type I have to use a special installer which in turn forces me to use Crystal Reports even though I really don't need it..
Led
I can promise you the sample I linked to doesn't use Crystal Reports (in fact I don't have Crystal installed at all). If you click the publish.htm link in my answer, it will install the DeepZoomViewer and file-associations - but definitely no Crystal Reports!If you are referring to this linkhttp://msdn.microsoft.com/en-us/library/ms227326.aspxit is part of the Crystal Reports documentation (!) which is why it mentions Crystal Reports. Sometimes Google doesn't give you "exactly" the right page...
CraigD
Ah, in that case I'll have another look, thanks !!Still I'm leaving this open as I think there should be a normal way (without ClickOnce) to register filetype associations from C# code in the OS, be it XP or Vista....
Led