0

I'm currently trying to get the file type associations for ALL (I know big ask) File type associations on a machine, store this in a list (or dictionary if this is better?) then compare this against a list after an application has been installed (new list, new snapshot of associations) and outputs any differences in a new list (so a total of 3 lists, beforeinstall, afterinstall, comparelist)

For an example scenario: - Adobe Acrobat is associated with .pdf. So I have a snapshot of all associations with .pdf as acrobat.

I then install Adobe Reader - this takes the .pdf association and I run the list again and I have a list now with reader on the .pdf

I can then run a compare and output the differences and output this into a new format (listview/textfile)

I'd normally provide a code sample but in all honesty I haven't a clue where to start - I've looked around and can mainly find how to add an fta which is not what I want.

Cheers

  • Please check these: http://stackoverflow.com/questions/6609640/how-to-create-c-sharp-list-of-all-file-associationsfriendly-application-names, http://stackoverflow.com/questions/770023/how-do-i-get-file-type-information-based-on-extention-not-mime-in-c-sharp?lq=1 – Daniel Hilgarth Apr 02 '16 at 09:22

1 Answers1

1

Take a look at this Code Project article: System File Association

The author gets list containing all extensions registered on the machine:

var allExtensions = new List<string>();
RegistryKey root = Registry.ClassesRoot;

string[] subKeys = root.GetSubKeyNames();
foreach (string subKey in subKeys) // now it's better to use Linq
{
    if (subKey.StartsWith("."))
    {
        allExtensions.Add(subKey);
    }
}

And then gets associated progId:

FileAssociationInfo fa = new FileAssociationInfo(extension);
var progId = fa.ProgID; // .pdf progId is "SumatraPDF" (on my machine)

Hope it helps.

Romario
  • 168
  • 1
  • 7
  • Please don't provide link only answers. Those can become stale. You should post this as a comment or repeat the important parts in your answer – Daniel Hilgarth Apr 02 '16 at 09:22
  • @DanielHilgarth You're right. It's better to post this as a comment. But I don't have enough reputation :( – Romario Apr 02 '16 at 09:57
  • I seem to have gotten something working from this code, apologies for the slow reply I've been pretty busy! Will mark as the correct answer, thank you very much! – badatseesharp Apr 03 '16 at 18:40