Tuesday, May 1, 2012

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

 

Very long time and back to work, just for curiosity about 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 a ways to read the WMAppManifest.xml file using XML Parse API.

Consider below mentioned code snippet.

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;
        }

 


Download source code here - ReadWMAppManifest


Happy Coding


Thanks for your time.