private static void ExtractResourceToFile(string resourceName, string
filename)
{
if
(!System.IO.File.Exists(filename))
using (System.IO.Stream s =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (System.IO.FileStream fs
= new System.IO.FileStream(filename, System.IO.FileMode.Create))
{
byte[] b
= new byte[s.Length];
s.Read(b,
0, b.Length);
fs.Write(b, 0, b.Length);
}
}
ExtractResourceToFile("MergeCell.Interop.Excel.dll", "Interop.Excel.dll");
ExtractResourceToFile("MergeCell.Office.dll",
"Office.dll");
VB.Net中资源的名称为:项目默认命名空间.资源文件名
C#中则是:项目命名空间.资源文件所在文件夹名.资源文件名
例:
[C# code]
Assembly assm = Assembly.GetExecutingAssembly();
istr = assm.GetManifestResourceStream("项目命名空间.资源文件所在文件夹名.资源文件名");