wpf file embeded resource is readonly,Copy always will copy
发布时间:2020-12-14 04:39:43 所属栏目:大数据 来源:网络整理
导读: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(); v
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 = @".ResourceJsonData.json"; string jsonContent=File.ReadAllText(jsonFile); File.AppendAllText(jsonFile,jsonContent,Encoding.UTF8); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |