Tip: Embedding Resources in Assemblies
[Problem]: Many a times, you end up using large string constants (usually placed in text files) in your application code. Typical examples are XSLT templates, SQL scripts and so on. It doesn’t really look nice to have a string constant defined in a class which have a hundred lines of text to serve this purpose. You wouldn’t want to store them separately in external text files either, as you wouldn’t want users to see/edit the contents.
[A Solution]: One way to solve this issue is to embed the text file contents in the assembly as a resource and then extract them at runtime. To embed strings in the assembly, you can add the text file to the project, and in the properties of the file select “Embedded Resource” as the build action. Then, to extract the contents of the file from the assembly, you can call the GetManifestResourceStream method on the Assembly instance, and read the stream into a string variable conveniently using StreamReader. You are just done!
Of course, this method is justified if the strings you embed are quite large (say, at least a 1000 characters or so). Else, be happy to use class constants.