繁体   English   中英

有没有办法从代码写入自定义应用程序配置配置

[英]Is there a way to write to a Custom app.Config Configuration from code

到目前为止,我有:

<section name="PinnedPhotos" type="PhotoViewer.PinnedPhotos, PhotoViewer" allowLocation="true" allowDefinition="Everywhere"/>
<PinnedPhotos>
  <add location="Location1.jpg"/>
  <add location="Location2.jpg"/>
</PinnedPhotos>

在我的app.Config中

在我的代码中,我有:

 PinnedPhotos config = (PinnedPhotos)System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location).Sections["PinnedPhotos"];

但是我想从代码中更新和保存config ,例如添加更多照片以固定到现有列表中。 有没有办法做到这一点?

编辑

var isReadOnly = config.Photos.IsReadOnly();

返回False ...所以我想应该有一种方法可以写入此集合?

知道了:我需要将两个方法添加到我的收藏夹中:

    public void Add(string location)
    {
        PhotoElement pe = new PhotoElement(location);
        BaseAdd(pe);
    }
    public void Remove(string location)
    {
        BaseRemove(location);
    }

然后这只是一个调用案例:

config.CurrentConfiguration.Save();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM