zoukankan      html  css  js  c++  java
  • 在 .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("项目命名空间.资源文件所在文件夹名.资源文件名");

  • 相关阅读:
    重载小于号
    无聊的会议
    程序内存和时间
    对拍
    读入和输出优化
    codevs 3269 混合背包
    清北第三套题
    codevs 2188 最长上升子序列
    清北第二套题
    [COGS896] 圈奶牛
  • 原文地址:https://www.cnblogs.com/leavind/p/3670418.html
Copyright © 2011-2022 走看看