• C#资源文件管理


    1.右键项目点属性;

    2.点资源项,添加资源下拉框的添加现在文件,如下图:

    3.直接上代码获取并复制到指定文件夹下:

    private void button1_Click(object sender, EventArgs e)
    {
        byte[] drawing1 = global::资源文件管理.Properties.Resources.Drawing1;
        byte[] gateway = global::资源文件管理.Properties.Resources.gateway;
        byte[] textgateway = global::资源文件管理.Properties.Resources.textgateway;//不需要后缀名
        //string smno = global::资源文件管理.Properties.Resources.smno;
        List<byte[]> list = new List<byte[]>();
        list.Add(drawing1);
        list.Add(gateway);
        list.Add(textgateway);
        DirectoryInfo dir = new DirectoryInfo(Application.StartupPath).Parent.Parent;
        string target = dir.FullName + "\Resources";//资源文件路径
        string[] files = Directory.GetFiles(target);//资源文件夹里的所有文件
        for (int i = 0; i < files.Length; i++)
        {
            string str = Path.GetFileName(files[i]);//textgateway.exe
            CopyFileTo(@"c:	ext", str, list[i]);
        }
        this.Close();
    }
    
    /// <summary>
    /// 复制文件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="fileName"></param>
    /// <param name="fileBuffer"></param>
    private void CopyFileTo(string path, string fileName, byte[] fileBuffer)
    {
        using (FileStream file = new FileStream(path + fileName, FileMode.Create))
        {
            file.Write(fileBuffer, 0, fileBuffer.Length);
        }
    }
    
    /// <summary>
    /// 复制文件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="str"></param>
    public static void CopyFileTo(string path, string str)
    {
        using (StreamWriter sw = new StreamWriter(path))
        {
            sw.Write(str);
        }
    }
  • 相关阅读:
    rocketmq集群安装,配置,测试
    JavaScript 不重复的随机数
    新浪SAE数据库信息wordpress设置(用户&密码&主地址)
    条件注释判断浏览器版本<!--[if lt IE 9]>
    SQL中Where与Having的区别
    linux进程内存到底怎么看 剖析top命令显示的VIRT RES SHR值
    linux top命令VIRT,RES,SHR,DATA的含义
    进程状态解析
    mysqldump 参数
    Oracle--通配符、Escape转义字符、模糊查询语句
  • 原文地址:https://www.cnblogs.com/genesis/p/5145089.html
Copyright © 2020-2023  润新知