Hi,
<ri***********@gmail.comwrote in message
news:11**********************@n2g2000hse.googlegro ups.com...
Hi
i have created a project that contains some class files and xml files
stored in resources. i have created dll of this project and am using
it in another project.
In other project i want to read the xml stored in the resources of
loaded project. Please tell me how can i extract xml file from the
resources of the loaded project (in dll).
static string ExtractResource( string resourceName)
{
//look for the resource name
foreach( string currentResource in
System.Reflection.Assembly.GetExecutingAssembly(). GetManifestResourceNames(*)
)
if ( currentResource.LastIndexOf( resourceName) != -1 )
{
string fqnTempFile = System.IO.Path.GetTempFileName();
string path = System.IO.Path.GetDirectoryName( fqnTempFile);
string rootName= System.IO.Path.GetFileNameWithoutExtension(
fqnTempFile);
string destFile = path + @"\" + rootName + "." +
System.IO.Path.GetExtension( currentResource);
System.IO.Stream fs =
System.Reflection.Assembly.GetExecutingAssembly(). GetManifestResourceStream*(
currentResource);
byte[] buff = new byte[ fs.Length ];
fs.Read( buff, 0, (int)fs.Length);
fs.Close();
System.IO.FileStream destStream = new System.IO.FileStream ( destFile,
FileMode.Create);
destStream.Write( buff, 0, buff.Length);
destStream.Close();
return destFile;
}
throw new Exception("Resource not found : " + resourceName);
}