How to access Application Manifest (WMAppManifest.xml) file at runtime
This article explains how to access windows phone application Manifest file in Windows Phone 7 application
Article Metadata
Code Example
Source file: File:ReadWMAppManifest.zip
Tested with
SDK: Windows Phone 7.1
Devices(s): "Nokia Lumia 710"
Compatibility
Platform(s): Windows Phone 7
Article
Created: pavan.pareta
(02 Jun 2012)
Last edited: hamishwillee
(30 Nov 2012)
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;
}

