Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the application name by code?

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

like image 772
Alesqui Avatar asked Dec 16 '22 16:12

Alesqui


2 Answers

var package = Windows.ApplicationModel.Package.current;
var displayName = package.displayName;

Added in 8.1

like image 66
sturrockad Avatar answered Dec 31 '22 10:12

sturrockad


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;
        });
    });
})();
like image 21
Jon Davis Avatar answered Dec 31 '22 10:12

Jon Davis