zoukankan      html  css  js  c++  java
  • 备份一个有的时候,可能需要把其它exe或者dll包含在主程序中....

    1、选中附件,右键生成操作选择  嵌入的资源,例如:handle.exe

    2、FileUtil

     1 using System.IO;
     2 using System.Reflection;
     3 
     4 namespace ResourceOccupancyHelp
     5 {
     6     public class FileUtil
     7     {
     8         /// <summary>
     9         /// 从资源文件中抽取资源文件
    10         /// </summary>
    11         /// <param name="resFileName">资源文件名称(资源文件名称必须包含目录,目录间用“.”隔开,最外层是项目默认命名空间)</param>
    12         /// <param name="outputFile">输出文件</param>
    13         public static void ExtractResFile(string resFileName, string outputFile)
    14         {
    15             BufferedStream inStream = null;
    16             FileStream outStream = null;
    17             try
    18             {
    19                 Assembly asm = Assembly.GetExecutingAssembly(); //读取嵌入式资源
    20                 inStream = new BufferedStream(asm.GetManifestResourceStream(resFileName));
    21                 outStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
    22 
    23                 byte[] buffer = new byte[1024];
    24                 int length;
    25 
    26                 while ((length = inStream.Read(buffer, 0, buffer.Length)) > 0)
    27                 {
    28                     outStream.Write(buffer, 0, length);
    29                 }
    30                 outStream.Flush();
    31             }
    32             finally
    33             {
    34                 if (outStream != null)
    35                 {
    36                     outStream.Close();
    37                 }
    38                 if (inStream != null)
    39                 {
    40                     inStream.Close();
    41                 }
    42             }
    43         }
    44     }
    45 }
    View Code

    3、调用demo

    FileUtil.ExtractResFile("ResourceOccupancyHelp.handle.exe", System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "handle.exe"));

    特别注意,生成的exe需要用命名空间最前缀,如果有文件夹的话也需要完整加上。

  • 相关阅读:
    团队开发day09
    团队开发day08
    团队开发day07
    python 字符串操作,获取任意字符串的方法(开头,结尾开始)
    ERIKA OS学习和使用总结
    解决win7无法正常进入睡眠的问题
    简单实用的Makefile
    js 签字插件
    html2canvas实现截取指定区域或iframe的区域
    jquery监听动态添加的input的change事件
  • 原文地址:https://www.cnblogs.com/xuling-297769461/p/14480873.html
Copyright © 2011-2022 走看看