Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to access Application Manifest (WMAppManifest.xml) file at runtime

From Wiki
Jump to: navigation, search

This article explains how to access windows phone application Manifest file in Windows Phone 7 application

WP Metro Icon File.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
SDK: Windows Phone 7.1
Devices(s): "Nokia Lumia 710"
Compatibility
Platform(s): Windows Phone 7
Windows Phone 7.5
Article
Created: pavan.pareta (02 Jun 2012)
Last edited: hamishwillee (28 Jun 2013)

Introduction

How to access “WMAppManifest.xml”; using silverlight c# code in Windows Phone application. In this article we will discuss Application Manifest file called WMAppManifest.xml file and it is available in Properties folder of your project in the Solution Explorer. Manifest file contains details about the application, such as the App ID Title, RuntimeType, Version, Genre, Author, Description, Publisher and the application capabilities.

Here is few approach to access WMAppManifest.xml file.

1 - Linq approach :

 private string ReadWMAppManifest()
{
string wmData = string.Empty;
System.Xml.Linq.XElement appxml = System.Xml.Linq.XElement.Load("WMAppManifest.xml");
var appElement = (from manifestData in appxml.Descendants("App") select manifestData).SingleOrDefault();
 
if (appElement != null)
{
wmData = "ProductID = " + appElement.Attribute("ProductID").Value + Environment.NewLine;
 
wmData += "Title = " + appElement.Attribute("Title").Value + Environment.NewLine;
wmData += "RuntimeType = " + appElement.Attribute("RuntimeType").Value + Environment.NewLine;
wmData += "Version = " + appElement.Attribute("Version").Value + Environment.NewLine;
wmData += "Genre = " + appElement.Attribute("Genre").Value + Environment.NewLine;
wmData += "Author = " + appElement.Attribute("Author").Value + Environment.NewLine;
wmData += "Description = " + appElement.Attribute("Description").Value + Environment.NewLine;
wmData += "Publisher = " + appElement.Attribute("Publisher").Value + Environment.NewLine;
}
 
appElement = (from manifestData in appxml.Descendants("PrimaryToken") select manifestData).SingleOrDefault();
 
if (appElement != null)
{
wmData += "TokenID = " + appElement.Attribute("TokenID").Value + Environment.NewLine;
}
 
return wmData;
}

2 - Linq approach using single line statement :

string strTitle = (from manifest in System.Xml.Linq.XElement.Load("WMAppManifest.xml").Descendants("App") select manifest).SingleOrDefault().Attribute("Title").Value;

3 - XML approach :

private string GetDataXMLApproach()
{
string wmData = string.Empty;
 
StreamResourceInfo xml = App.GetResourceStream(new Uri("WMAppManifest.xml", UriKind.Relative));
XmlReader reader = XmlReader.Create(xml.Stream);
 
 
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "App")
{
while (reader.MoveToNextAttribute())
{
wmData += reader.Name + " : " + reader.Value + Environment.NewLine;
}
 
}
}
}
 
return wmData;
}
This page was last modified on 28 June 2013, at 09:14.
223 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×