zoukankan      html  css  js  c++  java
  • wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder

    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); 
            }
  • 相关阅读:
    Ynoi 杂题选做
    CSP-S2021 浙江 游记
    P6272 [湖北省队互测2014]没有人的算术
    P5206 [WC2019]数树
    P5405 [CTS2019]氪金手游
    LOJ6679 Unknow
    LOJ3040 「JOISC 2019 Day4」合并
    P6122 [NEERC2016]Mole Tunnels
    三维凸包
    三,四元环计数
  • 原文地址:https://www.cnblogs.com/Fred1987/p/11655133.html
Copyright © 2011-2022 走看看