473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Working with an Embedded XML File

Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly.
I'm more than certain that I'm missing some sort of name space element in
the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that explains
how to create the xml file correctly and the code to read the embedded xml
file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay

Nov 12 '05 #1
2 19428
If you've compiled the XML file as an embedded resource then you can do
something like this:
using System;
using System.IO;
using System.Reflection;
using System.Xml;

class Application
{
static void Main(string[] args) {

Stream s =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("CSharpConsole.XML
File1.xml");

XmlDocument xdoc = new XmlDocument();

StreamReader reader = new StreamReader(s);

xdoc.LoadXml(reader.ReadToEnd());

reader.Close();

}
}

or:

Imports System.Xml
Imports System.Reflection
Imports System.IO

Module Main

Sub Main()

Dim s As Stream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("XMLFile1.xml")

Dim xdoc As New XmlDocument

Dim reader As New StreamReader(s)

xdoc.LoadXml(reader.ReadToEnd())

reader.Close()

End Sub

End Module

Notice in C# you have to prepend the project name (this is not a namespace)
to the file name. IIRC this is due to the way the VB compiler stores
resources in the assembly.

--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Jay Douglas" <RE*****************@squarei.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly.
I'm more than certain that I'm missing some sort of name space element in
the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that explains how to create the xml file correctly and the code to read the embedded xml
file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay

Nov 12 '05 #2
Perfect.

Thanks a ton.
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:eg**************@TK2MSFTNGP12.phx.gbl...
If you've compiled the XML file as an embedded resource then you can do
something like this:
using System;
using System.IO;
using System.Reflection;
using System.Xml;

class Application
{
static void Main(string[] args) {

Stream s =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("CSharpConsole.XML File1.xml");

XmlDocument xdoc = new XmlDocument();

StreamReader reader = new StreamReader(s);

xdoc.LoadXml(reader.ReadToEnd());

reader.Close();

}
}

or:

Imports System.Xml
Imports System.Reflection
Imports System.IO

Module Main

Sub Main()

Dim s As Stream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("XMLFile1.xml")

Dim xdoc As New XmlDocument

Dim reader As New StreamReader(s)

xdoc.LoadXml(reader.ReadToEnd())

reader.Close()

End Sub

End Module

Notice in C# you have to prepend the project name (this is not a namespace) to the file name. IIRC this is due to the way the VB compiler stores
resources in the assembly.

--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Jay Douglas" <RE*****************@squarei.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly. I'm more than certain that I'm missing some sort of name space element in the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that

explains
how to create the xml file correctly and the code to read the embedded xml file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: james | last post by:
What class / method should I be using to get the full path to an embedded resource ? In my case I have an .xml file that my app uses, it is set as embedded resource, and I have a control that...
4
by: Patrick Blackman | last post by:
I have a text file embedded in my dll, how can I load that file without using the GetManifestResourceStream of the Assembly class, I want to read it as if it was just located in my c:\my document...
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
4
by: Axter | last post by:
Sorry for OT question, but does any one have a working *.bat file to get Comeau to work with VC++ 7.1, VC++ 8.0, or GNU 3.x compilers. I've tried everything I can think off, to get it to work,...
5
by: Max | last post by:
hi i have file browser control to select any file and a button to upload file on my web page now when i select any file. now on click of upload button i have check that file exist or no if...
0
by: satish | last post by:
Hi, I have an issue ..i have a text which has the information of 4 test files and they are placed in the order 4 --- this number says (total no of text files) File1 1370 -- Memory of the text...
0
by: andreas2411 | last post by:
Hi, I have a file which I would like to put on the clipboard so that it is pasted in Word or WordPad the file appears as an embedded file. I can use the RichTextBox to generate RichText with...
2
Frinavale
by: Frinavale | last post by:
I am attempting to use embedded resources in an Ajax Enabled ASP.NET Web Application. I'm using Visual Studio 2008 and VB.NET server side code. The project is called "EmbeddedResources" with the...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
0
by: Belsirk | last post by:
Hi, i'm using C# Visual Studio 2008 for made a apps able to take some information from the app and sending them to a excel template, i'm using Microsoft.Office.Interop.Excel namespace and i don't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.