How can I get the application name by javascript code in a Windows 8 based app?
EDIT: Being more precise: I want the String in package.appxmanifest -> Application UI -> Display name
var package = Windows.ApplicationModel.Package.current;
var displayName = package.displayName;
Added in 8.1
Marco's answer was helpful, but converting to Javascript proved slightly difficult because of the poorly documented XML namespace requirement. LINQ-to-XML as with XDocument isn't available in WinJS but was used in Marco's referenced C# resource.
Here's how I got the app name. Note that it is asynchronous; AFAIK there is no synchronous way to get the application name.
var appname;
(function() {
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("AppxManifest.xml").then(function(file) {
Windows.Storage.FileIO.readTextAsync(file).done(function (text) {
var xdoc = new Windows.Data.Xml.Dom.XmlDocument();
xdoc.loadXml(text);
appname = xdoc.selectNodesNS("m:Package/m:Applications/m:Application/m:VisualElements",
"xmlns:m=\"http://schemas.microsoft.com/appx/2010/manifest\"")[0]
.attributes.getNamedItem("DisplayName").nodeValue;
});
});
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With