locked
FileOpenPicker: use file extensions from manifest RRS feed

  • Question

  • After specifying supported file extensions in the application manifest, I wonder how to access this information (maybe as a FileExtensionVector even) so I can use it in the FileOpenPicker. I was unable to find anything about that in the API but duplicating this list doesn't seem very DRY.
    Monday, March 12, 2012 9:54 AM

All replies

  • I had a couple of minutes to spare, so I came up with this quick and dirty code. It works but a method in the API that doesn't depend on the structure of the manifest would still be nicer of course.

      readExtensionsFromManifestAsync = function() {
        var applicationPath = Package.current.installedLocation.path;
        return StorageFile.getFileFromPathAsync(applicationPath + '\\package.appxmanifest').then(function(manifest) {
          return XmlDocument.loadFromFileAsync(manifest).then(function(doc) {
            var extensions, node, nodes, _i, _len;
            extensions = [];
            nodes = doc.selectNodesNS('descendant::mf:SupportedFileTypes/mf:FileType/text()', 'xmlns:mf="http://schemas.microsoft.com/appx/2010/manifest"');
            for (_i = 0, _len = nodes.length; _i < _len; _i++) {
              node = nodes[_i];
              extensions.push(node.nodeValue);
            }
            return extensions;
          });
        });
      };
    

    Monday, March 12, 2012 12:32 PM
  • Seems like a lot of work for little gain.  Since you defined the extension in your manifest and it is static, you know what it is so why not just code that into your app?

    Jeff Sanders (MSFT)

    Monday, March 12, 2012 1:32 PM
    Moderator
  • Because it's harder to maintain. Putting together a simple XPath seemed easier than someday forgetting to add an extension in multiple places at once. Also it just doesn't seem right to duplicate information that is already there ^^
    Tuesday, March 13, 2012 8:47 AM