zoukankan      html  css  js  c++  java
  • wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder

    Wpf file embeded resource will compile the file into the assembly and it will be readonly and can not be writable.

    using System.IO;
    using System.Reflection;
    
     void ReadEmbededResourceDemo()
            {          
                var assembly = Assembly.GetExecutingAssembly();
                var names = assembly.GetManifestResourceNames();
                var resourceName = "WpfApplication7.Resource.JsonData.json";
               
                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string result = reader.ReadToEnd();
                    MessageBox.Show(result);
                }
            }

    While you set the file as Copy always it will copy the file and its folder to *.exe location.

     void WriteResourceAlwaysCopy()
            {
                string dir = Directory.GetCurrentDirectory();
                var allFiles=Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
                var jsonFile = @".ResourceJsonData.json";
                string jsonContent=File.ReadAllText(jsonFile);
                File.AppendAllText(jsonFile, jsonContent, Encoding.UTF8); 
            }
  • 相关阅读:
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    .net 5.0
    redis
    分布式同步服务中间件
  • 原文地址:https://www.cnblogs.com/Fred1987/p/11655133.html
Copyright © 2011-2022 走看看