Click here to Skip to main content
13,410,470 members (35,028 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 10 Sep 2012

How to Access Manifest (Embedded) Resources from an Assembly in a WinRT Application

, 10 Sep 2012
Rate this:
Please Sign up or sign in to vote.
How to access a simple XML file embedded in the WinRT assembly

In this blog post, I am going to demonstrate how to access a simple XML file embedded in the WinRT assembly.

One of the easier ways to retrieve an assembly in .NET application is by using the below method:

// This will return the assembly whose code is currently executing. 

Alternate one is to use Type object of the classes present in the assembly.

Assembly assembly = typeof(DemoClass).GetType().Assembly;

From the assembly object, we can retrieve the manifest resource stream (embedded file) using GetManifestResourceStream() method. All we need is to pass the name of the embedded resource. The name of the embedded resource is the combination of root namespace, folder path and the file name.

For example, consider the root namespace of a demo application to be MyApp and the XML file (Embedded.xml) is available under Resources folder of the assembly. Then, the name of the embedded resource is “MyApp.Resources.Embedded.xml”.

Sample Code Snippet for .NET

Assembly assembly = Assembly.GetExecutingAssembly();


Assembly assembly = typeof(DemoClass).GetType().Assembly;
Stream xmlStream = assembly.GetManifestResourceStream("MyApp.Resources.Embedded.xml");

In WinRT, both GetExecutingAssembly() and GetType().Assembly are not available, instead you can retrieve the assembly object from the classes declared in the assembly by means of using TypeInfo object. Now the remaining part to access the manifest resource is the same as in a .NET application. Please find the code snippet from below.

Sample Code Snippet for WinRT

Assembly assembly = typeof(DemoClass).GetTypeInfo().Assembly;
Stream xmlStream = assembly.GetManifestResourceStream("MyApp.Resources.Embedded.xml");

Please find the demo application from this link. In this application, embedded XML file is retrieved and its contents are displayed in a text box.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead Syncfusion
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWindows 10 Pin
Benoit Lacert6-Aug-15 11:16
memberBenoit Lacert6-Aug-15 11:16 
GeneralMy vote of 5 Pin
Farhan Ghumra6-Jan-13 20:08
memberFarhan Ghumra6-Jan-13 20:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180221.1 | Last Updated 10 Sep 2012
Article Copyright 2012 by rajendran_sp
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid