You must Sign In to post a response.
  • Category: .NET

    How to edit values of app.config file from another application?

    Hello everyone,

    I have two windows application project says "A" and "B" in same solution. I already sets all key values in app.config file of "A" . Now I got requirement that I have to make one exe says winform contaings textboxes where I have to set all key values for app.config file of "A" . this exe is my project "B". now i tried many ways to get access of config file of project A . but i failed. I also tried with "ConfigurationManager.OpenExeConfiguration(path)" but here needs file path which i could not put hardcoded. I am restricted to put any hardcoded paths.

    note: I created setup project and added both projects output so that both projects exes and app.config of "A" will be in same folder so that its easy to locate file.

    Is there any way to achieve this.
    Please suggest me ,
    Thanks to everyone.

    Hide Copy Code
    <add key="DataSource" value="ADMIN-PC"/>
    <add key="DBname" value="DATA_ABHISHEK"/>
    <add key="Security" value="True"/>
    <add key="UserName" value=""/>
    <add key="Passward" value=""/>
    <add key="hourrate" value="60"/>
    <add key="port" value="2030"/>

    I have above config file and i want to change its key values like "ADMIN-PC" by winform app. which contains form tanking text from textbox.
  • #762919
    Hello Priyanka Barwad,

    Is this configuration to connect to MySql Database. If it is than i have the solution for it. Let me know if you are looking to create the connection string dynamically..??

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762959
    Yes this config file is for connection to database and i created one form (like registration form) which needs to set values of this file . both projects are in same solution .

  • #762960
    Hello Priyanka,

    app.config file :

    <add name="mycon"
    providerName="MySql.Data.MySqlClient" />

    Code - behind :

    using System.Configuration;
    using System.IO;
    using MySql.Data.MySqlClient;
    using System.Xml;

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    MySqlConnectionStringBuilder sqlBuilder = new MySqlConnectionStringBuilder();
    sqlBuilder.Server = "";
    sqlBuilder.UserID = "nirav";
    sqlBuilder.Password = "Pass@1234";
    sqlBuilder.PersistSecurityInfo = true;
    sqlBuilder.Database = "employees";
    sqlBuilder.Port = "3306";
    config.ConnectionStrings.ConnectionStrings["mycon"].ConnectionString = sqlBuilder.ConnectionString;
    config.Save(ConfigurationSaveMode.Modified, true);

    Login l = new Login(databasename);

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

Sign In to post your comments