Adding files to Assembly

  • Thread starter Thread starter Ron M. Newman
  • Start date Start date
R

Ron M. Newman

Hello .NET Sages,

Question.

What is the meaning of adding say, an XML file to a project, next to a .CS
file (not that it matters). Does that mean the XML file becomes a part of
the compiled assembly and I'll be able to refer to it from another
application that'll open up and use this assembly?

As you understand, this is my purpose. I'd like to have an assembly that
builds with fixed XML files that I'd like to access from an application
referring to this assembly. Is the way mentioned earlier the right way to do
so? How do I retrieve the file later?

Thanks
Ron
 
Ron said:
Hello .NET Sages,

Question.

What is the meaning of adding say, an XML file to a project, next to a .CS
file (not that it matters). Does that mean the XML file becomes a part of
the compiled assembly and I'll be able to refer to it from another
application that'll open up and use this assembly?

As you understand, this is my purpose. I'd like to have an assembly that
builds with fixed XML files that I'd like to access from an application
referring to this assembly. Is the way mentioned earlier the right way to do
so? How do I retrieve the file later?

Thanks
Ron

Yes, the XML (bmp, ico, ...) file becomes part of the compiled assembly.
If you use Reflector (http://www.aisto.com/roeder/dotnet/) tool you can
open your assembly and you will find your file in Resources section.

You add your file in C# project and then set BuildAction property to
"EmbeddedResource". This way the file will be included into assembly,
but not compiled.

To access the content of the file use something like:
StreamReader loStreamReader;
loStreamReader = new
StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.Data.XML"));

Replace "Assembly.GetExecutingAssembly()" with some other way of getting
System.Reflection.Assembly instance.

Hope it helps,
Petar Repac
 
Back
Top