Your question is rather vague ... but it looks like you want to get the text content of an embedded resource. You usually do this using Assembly.GetManifestResourceStream . You can always use LINQ with Assembly.GetManifestResourceNames() to find the name of the embedded file that matches the pattern.
The ResourceManager class is often used to automatically retrieve localized string resources, such as labels and error messages in different languages.
update: a more general example:
internal static class RsrcUtil { private static Assembly _thisAssembly; private static Assembly thisAssembly { get { if (_thisAssembly == null) { _thisAssembly = typeof(RsrcUtil).Assembly; } return _thisAssembly; } } internal static string GetNlogConfig(string prefix) { return GetResourceText(@"Some\Folder\" + prefix + ".nlog.config"); } internal static string FindResource(string pattern) { return thisAssembly.GetManifestResourceNames() .FirstOrDefault(x => Regex.IsMatch(x, pattern)); } internal static string GetResourceText(string resourceName) { string result = string.Empty; if (thisAssembly.GetManifestResourceInfo(resourceName) != null) { using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName)) { result = new StreamReader(stream).ReadToEnd(); } } return result; } }
Using an example:
string aconfig = RsrcUtil.GetNlogConfig("a"); string bconfigname = RsrcUtil.FindResource(@"b\.\w+\.config$"); string bconfig = RsrcUtil.GetResourceText(bconfigname);
source share