The mysteries of software development and networking... RSS 2.0



 Tuesday, June 13, 2006

I knew it was possible, but never took the time to have a closer look at how to do it.

With embedded resources you can embed whole files (binary and text) in your assembly. Today I created a Console application that provides help when you pass the '/?' switch. The helpfile is a plain textfile, embedded in the assembly.

Here's how it is done:

  1. Add the textfile to your project.
  2. Set the property 'Build Action' to 'Embedded Resource'.
  3. Use code below to retrieve file as string.

private static string GetFileFromResources(string filename)
{
Assembly assembly;
assembly = Assembly.GetExecutingAssembly();
Stream stream =
assembly.GetManifestResourceStream("Type assembly namespace here" + "." + filename);
StreamReader sr = new StreamReader(stream);
string file = sr.ReadToEnd();
return file;
}

Tuesday, June 13, 2006 10:05:33 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C# | General
Comments are closed.
About
This blog is run by Mark Blomsma.
© Copyright 2008
Develop-One
Sign In
Statistics
Total Posts: 337
This Year: 81
This Month: 0
This Week: 1
Comments: 94
All Content © 2008, Develop-One
DasBlog theme 'Business' created by Christoph De Baene (delarou)