欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-22 10:43:12
Wpf file embeded resource will compile the file into the assembly and it will be readonly and can not be writable. While you set the file as Copy alwa ......

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