在安装设置文件后如何使用c#重新接受安装后如何接受app.confirg文件中的用户更改 [英] How to accept User changes in app.confirg file after instalation the setup file with out recomplilation using c#

查看:61
本文介绍了在安装设置文件后如何使用c#重新接受安装后如何接受app.confirg文件中的用户更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,有人帮我吗
iam创建了一个C#Windows应用程序设置.然后将其安装在用户系统中.
在这里我想接受来自app.config文件的更改,这是我的用户更改图像文件夹的位置.第一次我的exe文件接受在appsettings中修改过的更改.
问题是第二次是下次它不接受app.config文件中的用户更改.为什么在我的设置创建过程中会发生任何错误的IAM ?.
请验证此代码并为此提供合适的示例.
这是我的代码



Hello anybody help me
iam created one c# windows application setup.Then installed in user system.
here i want to accept changes from app.config file that is my user change image folder location.first time my exe file accepting changes where iam modified in appsettings .
the problem is second are next time it is not accept user changes in app.config file. why it is happen any wrong iam doing in my setup creation?.
plz verify this code and give suitable examples for this.
Here is my code



<appsettings>
    <add key="SQLCN" value="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=True" />
    <add key="IMGFOLDER" value="D:\\ImageFolder" />
</appsettings>





private void SaveToIsolatedStorage(XDocument document, string file)
{
    // Open the stream from IsolatedStorage.
    IsolatedStorageFileStream stream = new IsolatedStorageFileStream(
        file, FileMode.Create, GetUserStore());
    using (stream)
    {
        using (StreamWriter writer = new StreamWriter(stream))
        {
            document.Save(writer);
        }
    }
}
 
fldr = ConfigurationSettings.AppSettings["IMGFOLDER"];
Formload()
{
    NewImageFolderCreation();
    PopulateTreeview();
}
 
btnImagesave()
{
    SaveImageAfterConvertion();
}
 
private void NewImageFolderCreation()
        {
            if (!System.IO.Directory.Exists(fldr))
            {
                System.IO.Directory.CreateDirectory(fldr);
                MessageBox.Show("folder created");
            }
            else
            {
                MessageBox.Show("ImageFolder is available populate images into folder");
            }
        }  
 
private void POpulateTreeview()
        {
            DirectoryInfo info = new DirectoryInfo(fldr);
            TreeNode root = new TreeNode(info.Name);
            root.Text = "";
            //eng = OcrEngineManager.CreateEngine(OcrEngineType.Professional, false);
            //eng.Startup(null, null, null, null);
            TreeNode node = new TreeNode();
            TrvImageFile.Nodes.Add(root);
            FileInfo[] subfileinfo = info.GetFiles("*.*");
            if (subfileinfo.Length > 0)
            {
                for ( j = 0; j < subfileinfo.Length; j++)
                {
                    root.Nodes.Add(subfileinfo[j].Name);
                }
            }
            TrvImageFile.ExpandAll();
        }
 
SaveImageAfterConvertion()
{
if (!System.IO.Directory.Exists(fldr))
            {
                System.IO.Directory.CreateDirectory(fldr);
                doc.Save(ConfigurationSettings.AppSettings["SaveImagefolderPath"] + "\\" + Newtxtfilename + ".txt", Leadtools.Forms.DocumentWriters.DocumentFormat.Text, null);
                MessageBox.Show("folder created and image output saved");
            }
            else
            {
                doc.Save(ConfigurationSettings.AppSettings["SaveImagefolderPath"] + "\\"  +Newtxtfilename + ".txt", Leadtools.Forms.DocumentWriters.DocumentFormat.Text, null);
                MessageBox.Show("ImageFolder is available  images are  Saved into folder Now");
            }    
}

推荐答案

设置不会自动保存,您应该手动保存.
您可以使用下一个代码来保存AppSettings:

Settings not saved automatically, you should save it manually.
You can use next code for saving AppSettings:

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");


这篇关于在安装设置文件后如何使用c#重新接受安装后如何接受app.confirg文件中的用户更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆