wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folde

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

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.spa

 void WriteResourceAlwaysCopy()
        {
            string dir = Directory.GetCurrentDirectory();
            var allFiles=Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
            var jsonFile = @".\Resource\JsonData.json";
            string jsonContent=File.ReadAllText(jsonFile);
            File.AppendAllText(jsonFile, jsonContent, Encoding.UTF8); 
        }
相關文章
相關標籤/搜索