1

As a follow-up to Filesystem Hook for .doc open C# i'm trying to figure out the following for a WPF application.

I want to replace the file association for .doc & .docx with my own program which will run at windows start-up.

My program will then simply open a word with the documented requested but with the added benefit of being able to hook into events like Office.Interop.Word.DocumentOpen - this way i'll be able to get everything thats ever opened by word without a filesystemwatcher or something similar.

What is the best practice way of doing this and how do I overwrite Words' association with the file?

Community
  • 1
  • 1
Mrk Fldig
  • 4,244
  • 5
  • 33
  • 64

1 Answers1

1

use these two commands

ftype and assoc

Run Command Prompt Commands

Community
  • 1
  • 1
Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
  • Hrm ok that looks pretty good, let me do some checking on how i'd get return status for it – Mrk Fldig Nov 07 '14 at 17:25
  • also "ftype /?" in cmd may come in hande – Hamid Pourjam Nov 07 '14 at 17:27
  • Yeah that actually looks very interesting since it means i don't have to mess around with figuring out the version of office, which has knock on benefits for my software, i'm just checking if I can grab the output from command and check it executed ok – Mrk Fldig Nov 07 '14 at 17:29
  • Hrm if I do ftype .doc = it deletes the association but when I click on .doc it still opens it with word – Mrk Fldig Nov 07 '14 at 17:36
  • 1
    Ahh hold on I was being a dumb ass two ticks its ftype .doc Word.Document.8= – Mrk Fldig Nov 07 '14 at 17:42
  • os version? office version? – Hamid Pourjam Nov 07 '14 at 17:43
  • Windows 8.1 office 2013 - looks like ftype/assoc should be fine down till vista? Looks like you're heading nicely toward a winner here! – Mrk Fldig Nov 07 '14 at 17:44
  • I think all versions of windows >= xp support them – Hamid Pourjam Nov 07 '14 at 17:47
  • 1
    Providing I can reliably execute these in C# i'll tick this, the added benefit is I can determine which version of office is in use which really helps with other aspects, its possible I actually love you – Mrk Fldig Nov 07 '14 at 17:48
  • 1
    Right i'm gonna mark this as correct since I can execute these commands from a batch file if needed and then get the result from the batch file output. Thanks! – Mrk Fldig Nov 07 '14 at 19:36
  • Solition here with an update for windows 8/10 http://stackoverflow.com/questions/2681878/associate-file-extension-with-application/40405884#40405884 – sofsntp Jan 31 '17 at 16:14