Reputation: 6439
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
Upvotes: 4
Views: 2858
Reputation: 4550
var package = Windows.ApplicationModel.Package.current;
var displayName = package.displayName;
Added in 8.1
Upvotes: 5
Reputation: 6753
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;
});
});
})();
Upvotes: 4
Reputation: 5225
According to this reference, there is no way to get the display name. You can get the package name from Package.Id, but it sounds like you want the display name.
Upvotes: 2
Reputation: 812
You can take a look to the AppManifestHelper class that is included in the Callisto Control Toolikit. The GetManifestVisualElementsAsync method returns a VisualElement object with the property DisplayName, that is what you're looking for.
Note that this code is in C#, so you need to convert it to Javascript.
Upvotes: 1