Skip to content

Instantly share code, notes, and snippets.

@mishrsud
Last active August 29, 2015 14:16
Show Gist options
  • Save mishrsud/9d7069f706b8370d05e5 to your computer and use it in GitHub Desktop.
Save mishrsud/9d7069f706b8370d05e5 to your computer and use it in GitHub Desktop.
Gets an Embedded Resource (text) from currently executing assembly
/// <summary>
/// Reads text that is embedded into an assembly
/// </summary>
/// <remarks>
/// fullyQualifiedFileName is fully qualified, e.g. if the file abc.config was in assembly with namespace MyCompany.MyLib inside a
/// folder Config then fullyQualifiedFileName should read MyCompany.MyLib.abc.config
/// </remarks>
private static string GetTextFromEmbededResource(string fullyQualifiedFileName)
{
var assembly = Assembly.GetExecutingAssembly();
var result = string.Empty;
using (var stream = assembly.GetManifestResourceStream(fullyQualifiedFileName))
{
if (stream == null) return result;
var reader = new StreamReader(stream);
result = reader.ReadToEnd();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment