当前位置: 移动技术网 > IT编程>开发语言>.net > wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder

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

2019年10月12日  | 移动技术网IT编程  | 我要评论

玻儿,雪之梦下载,sihu

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

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网