473,466 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 19431
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...
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,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.