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); }
上一篇: 结构型设计模式(上)
下一篇: PHP学习—了解篇