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

2022-10-14,,,

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 = @".\resource\jsondata.json";
            string jsoncontent=file.readalltext(jsonfile);
            file.appendalltext(jsonfile, jsoncontent, encoding.utf8); 
        }

 

《wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder.doc》

下载本文的Word格式文档,以方便收藏与打印。