Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept User changes in app.config file after installing the setup file?

Tags:

c#

I have created one c# windows application setup.Then installed in user system.
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 I have modified in appsettings.

The problem is it does not accept user changes in app.config file. Why does this happen? What is wrong in my setup creation? Please verify this code and give a 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");
         }    
     }
like image 961
vali Avatar asked Jan 20 '26 17:01

vali


1 Answers

The whole point of a configuration file is that you can make changes without recompiling.

When in comes to winforms, you need to ensure the correct config file is changed (it is rarely named app.config - it is normally <name of app>.exe.config.

The app.config file you see in visual studio is a template - when compiling the application it will be copied to the output folder and renamed to <name of app>.exe.config. This is the file that should be changed.

The user will normally need to exit from the application and restart in order for the changed configuration settings to take hold.

like image 125
Oded Avatar answered Jan 23 '26 05:01

Oded