• 在 .net 中释放嵌入的资源


    image

    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("项目命名空间.资源文件所在文件夹名.资源文件名");

  • 相关阅读:
    1434. Buses in Vasyuki 夜
    SAP
    目标
    组合数
    KM算法模板
    网络流
    CodeForces 43E
    B. Unsorting Array codeforces 127
    Colorful Rainbows 127
    C. Anagram codeforces
  • 原文地址:https://www.cnblogs.com/leavind/p/3670418.html
Copyright © 2020-2023  润新知