Is there any support in the Windows or .NET for Windows Store apps API:s that allow me to list which file type associations that are defined for the executing app?
In my scenario, I have a Windows Store Class Library that I intend to reference from various Windows Store apps. Ideally, I want to be able to read the defined file type associations of the app within a class library method. Is this possible?
To date, there seems to be no built-in way to access the file type associations of a Windows Store app, but I have been able to implement a workaround thanks to this blog post.
Apparently the Package.appxmanifest file is transformed into a file AppxManifest.xml that is distributed with the deployed app. Among many things, the manifest file contains the user-defined file type associations for the app, so simple XML query can be used to obtain these definitions:
var document = XDocument.Load("AppxManifest.xml");
var xname = XNamespace.Get("http://schemas.microsoft.com/appx/2010/manifest");
var fileTypeElements =
document.Descendants(xname + "FileTypeAssociation").Descendants().Descendants();
var supportedFileExtensions =
fileTypeElements.Select(element => element.Value).ToArray();
This code can certainly be further fine-tuned, for example the FileTypeAssociation node is a (deep) descendant of the Application node, of which there can be more than one in the same manifest file. Nevertheless, the above code should at least be able to serve as a first-attempt approach.