Embedding a file into a project...

  • Thread starter Thread starter Andrew Connell
  • Start date Start date
A

Andrew Connell

I have the need for a few XSLT files that I'd like to embed within my DLL. I don't want to be forced to have to deploy each of these XSLT files as well as my DLL... because if one file was missing, it could cause major problems.

How would I go about adding an XSLT file to an assembly and then, how to pull it out? Assuming it has something to do with the resource files.

-AC
 
Add the file to your project, and set its BuildAction property to Embedded
Resource. When the project is compiled, you'll be able to see a reference to
the embedded file using ILDASM - look in the manifest for the line that
begins with .mresource.

To load the file, use something like:
Assembly asm = Assembly.GetExecutingAssembly();
using(Stream s = asm.GetManifestResourceStream("namespace.filename.ext"))
{
// use stream here...
}
 
Back
Top