FileOpenPicker:使用清单中的文件扩展名 [英] FileOpenPicker: use file extensions from manifest
本文介绍了FileOpenPicker:使用清单中的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在应用程序清单中指定支持的文件扩展名后,我想知道如何访问此信息(甚至可以作为FileExtensionVector),以便我可以在FileOpenPicker中使用它。我无法在API中找到任何关于它的内容,但重复
此列表似乎不是很干。
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.
推荐答案
我有一对几分钟,所以我想出了这个快速而又脏的代码。它的工作原理,但API中的一个不依赖于清单结构的方法当然会更好。
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;
});
});
};
这篇关于FileOpenPicker:使用清单中的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文