Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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



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


C#
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");
            }    
}
Posted
Updated 20-Aug-11 1:59am
v2

1 solution

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900