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();

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 = @".\Resource\JsonData.json";
            string jsonContent=File.ReadAllText(jsonFile);
            File.AppendAllText(jsonFile, jsonContent, Encoding.UTF8); 


posted @ 2019-10-11 16:41  Fred1987  阅读(168)  评论(0编辑  收藏