471,627 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Resource Content

Hi All,

I have created a folder call Resource within my project, I have added a XML
file into the resource folder, and I set the BuildAction property of the XML
file to "Embedded Resource". How can I retrieve its content in the runtime?
Any help is deeply appreciated. Thanks you very much in advance.

Kate
Jan 10 '06 #1
6 2610
Hi,

It will be inside the .exe ( or dll )

You can use this code to retrieve it:

IIRC the full name would be the namespace +. + the name of the file, not
100% sure now though.

m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(
"TheNameOfTheImage.gif" ));

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"cql90" <cq***@yahoo.com> wrote in message
news:OT*************@TK2MSFTNGP09.phx.gbl...
Hi All,

I have created a folder call Resource within my project, I have added a
XML file into the resource folder, and I set the BuildAction property of
the XML file to "Embedded Resource". How can I retrieve its content in the
runtime? Any help is deeply appreciated. Thanks you very much in advance.

Kate

Jan 10 '06 #2
Thanks you very much for your responded, I am deeply appreciated. Your code
would work well for bitmap, but not for XML file. Take care and have a nice
day...

Kate,
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

It will be inside the .exe ( or dll )

You can use this code to retrieve it:

IIRC the full name would be the namespace +. + the name of the file, not
100% sure now though.

m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManife stResourceStream(
"TheNameOfTheImage.gif" ));

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"cql90" <cq***@yahoo.com> wrote in message
news:OT*************@TK2MSFTNGP09.phx.gbl...
Hi All,

I have created a folder call Resource within my project, I have added a
XML file into the resource folder, and I set the BuildAction property of
the XML file to "Embedded Resource". How can I retrieve its content in
the runtime? Any help is deeply appreciated. Thanks you very much in
advance.

Kate


Jan 10 '06 #3
Actually, his call to GetManifestResourceStream returns what it says --
a stream .... so whether your are feed that stream to an XML Reader or a
Bitmap constructor should work equally well.
cql90 wrote:
Thanks you very much for your responded, I am deeply appreciated. Your code
would work well for bitmap, but not for XML file. Take care and have a nice
day...

Kate,
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

It will be inside the .exe ( or dll )

You can use this code to retrieve it:

IIRC the full name would be the namespace +. + the name of the file, not
100% sure now though.

m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetMani festResourceStream(
"TheNameOfTheImage.gif" ));

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"cql90" <cq***@yahoo.com> wrote in message
news:OT*************@TK2MSFTNGP09.phx.gbl...
Hi All,

I have created a folder call Resource within my project, I have added a
XML file into the resource folder, and I set the BuildAction property of
the XML file to "Embedded Resource". How can I retrieve its content in
the runtime? Any help is deeply appreciated. Thanks you very much in
advance.

Kate



Jan 11 '06 #4

My project name is: Test. I did insert a folder call: "Resource" into my
project. I did insert an XML file into the resource folder, I set the
BuildAction of XML file to Embedded resource. After all, I do this:

try

{

System.Reflection.Assembly _Assembly =
System.Reflection.Assembly.GetExecutingAssembly();

StreamReader rd = new StreamReader( _Assembly .GetManifestResourceStream(
"Test.Resource.Configuration.xml" ) );

}

catch( Exception Err )

{

MessageBox.Show( Err.Message );

}

I am always get an error message said that: the "stream" cannot be null

Any ways, Thanks you so much for your help, John. I am very appreciated. I
did try the code but it doen't work. Take care and have a nice day.

"John Murray" <jm*****@pluck.com> wrote in message
news:um**************@TK2MSFTNGP14.phx.gbl...
Actually, his call to GetManifestResourceStream returns what it says --
a stream .... so whether your are feed that stream to an XML Reader or a
Bitmap constructor should work equally well.
cql90 wrote:
Thanks you very much for your responded, I am deeply appreciated. Your
code would work well for bitmap, but not for XML file. Take care and have
a nice day...

Kate,
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

It will be inside the .exe ( or dll )

You can use this code to retrieve it:

IIRC the full name would be the namespace +. + the name of the file, not
100% sure now though.

m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetMan ifestResourceStream(
"TheNameOfTheImage.gif" ));

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"cql90" <cq***@yahoo.com> wrote in message
news:OT*************@TK2MSFTNGP09.phx.gbl...

Hi All,

I have created a folder call Resource within my project, I have added a
XML file into the resource folder, and I set the BuildAction property of
the XML file to "Embedded Resource". How can I retrieve its content in
the runtime? Any help is deeply appreciated. Thanks you very much in
advance.

Kate


Jan 11 '06 #5
Hi,

I have never put the resource file in a folder.
Do this:

string[] resources = GetType().Assembly.GetManifestResourceNames()
You can then iterate in all the resources and see how it's named

Please post back your findings

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 11 '06 #6
Hi Ignacio Machin,

The reason why I put the resource in the folder because it will be cleanner.
I have images in one folder, xml files in another folder, and picture in
other folder. Now, you know why I have to put my xml file in a folder. it
works if I don't put my xml file in folder and the code look like this:

// Get the data from XML file and input into the stream

System.IO.Stream _stream = _Assembly.GetManifestResourceStream(
"Test.Configuration.xml" );

// Create read stream object so we can read data out from the stream

StreamReader _streamReader = new StreamReader( _stream );

// Make file name in current working environment

string strFilename = AppDomain.CurrentDomain.BaseDirectory +
"Configuration.xml";

// Create a file to write data from the stream to the file

StreamWriter _streamWriter = new StreamWriter( strFilename );

// Read all the data from stream and write to the file

_streamWriter.Write( _streamReader.ReadToEnd() );

// Close when finish

_streamReader.Close();

_streamWriter.Close();

// Create temporary process

System.Diagnostics.Process _Process = new System.Diagnostics.Process();

// Open the notepad file, read data from XML file and then paste data into
the notepad

System.Diagnostics.ProcessStartInfo _pcInfo = new

System.Diagnostics.ProcessStartInfo( "Notepad.exe", strFilename );

_pcInfo.UseShellExecute = false;

_pcInfo.RedirectStandardOutput = true;

_Process.StartInfo = _pcInfo;

// Start Nodepad

_Process.Start();

// Pause right here until the notepad is close

_Process.WaitForExit();

// Release the temporary process

_Process.Close();

// Create new fileinfo object

FileInfo _finfos = new FileInfo( strFilename );

// Delete file

_finfos.Delete();
Thanks you so much for your help, Ignacio. I am greatly appreciated. Take
care and have a nice day...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I have never put the resource file in a folder.
Do this:

string[] resources = GetType().Assembly.GetManifestResourceNames()
You can then iterate in all the resources and see how it's named

Please post back your findings

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jan 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gabriel Lozano-Mor醤 | last post: by
5 posts views Thread by Martin Bischoff | last post: by
2 posts views Thread by guoqi zheng | last post: by
1 post views Thread by schneider | last post: by
2 posts views Thread by Nesster13 | last post: by
1 post views Thread by Ryan Liu | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.