The following code works. My problem is that I don't want to have to
hardcode the string that I set resourceName to in the code. Is there a way
for me to determine the namespace of the assembly from the oAssembly object?
All I want is the string "MyTopNamespace.Helpers." I will of course hard
code the USStates.xml.
namespace MyTopNamespace.Helpers.SpecialCollections
{
public sealed class USCollections
{
private static DataTable FetchStateData()
{
// open the executing assembly
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();
// create stream for resource in assembly
// Make sure that the resource's build action in the project is set to
'Embedded Resource'
string resourceName = "MyTopNamespace.Helpers.USStates.xml";
System.IO.Stream docStream =
oAssembly.GetManifestResourceStream(resourceName);
DataSet ds = new DataSet();
ds.ReadXml(docStream, XmlReadMode.Auto);
ds.Tables[0].TableName = "USStates";
return ds.Tables[0].Copy();
}
}
}