Home
Manage Your Code
Snippet: Retrieve XmlNavigator from embedded resource (C#)
Title: Retrieve XmlNavigator from embedded resource Language: C#
Description: Use this to embed XML documents into your assemblies and pull them at run time. Just make sure to set the XML file Compile mode to "Embedded Resource" and feed in the full name of the file when you want to pull it out. Views: 238
Author: Michael Wood Date Added: 10/7/2007
Copy Code  
1public static XPathNavigator GetTestXmlNavigatorConfig(string testXmlFile)
2{
3    XmlDocument doc = new XmlDocument();
4    doc.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream(
5        string.Concat("TestAsseblyNamespaceHere.", mockXmlFile)));
6    return doc.CreateNavigator();
7}
Usage
XPathNavigator myTestConfig = GetTestXmlNavigatorConfig("MytestFileConfig.xml");