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

  • 相关阅读:
    Spark参数优化
    Spark性能优化指南
    Durid的特点
    优秀博客地址
    Kylin的特点
    2017/11/20
    堆、栈、静态存储
    arraylist 和 linkedlist 的区别
    青岛项目遇到的问题
    access specifier
  • 原文地址:https://www.cnblogs.com/leavind/p/3670418.html
Copyright © 2011-2022 走看看