How to access and modify the values of .config file with ini format by using c#?

Alison

I have a .config file with ini format called menu.config. I created a C# Web form Application in Visual Studio 2010, and I want to access/modify the values of this file. For example, edit Enable=1 to Enable=2 on [Menu 1]. I have no idea how to start it. Hope someone can give me some suggestions, thank you!

[Menu1]
Enabled=1
Description=Fax Menu 1

[Menu2]
Enabled=1
description=Forms
Shan Khan

I suggest you to store values in Web.config file and retrieve them in all application. U need to store them in app settings

<appSettings>
  <add key="customsetting1" value="Some text here"/>
</appSettings>

and retrieve them as :

string userName = WebConfigurationManager.AppSettings["customsetting1"]

If you want to read from specific file.

Use Server.Mappath for setting path. Following will be the code.

using System;
using System.IO;

class Test
{
    public void Read()
    {
        try
        {
            using (StreamReader sr = new StreamReader("yourFile"))
            {
                String line = sr.ReadToEnd();
                Console.WriteLine(line);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to modify .INI file with using sharpconfig?

From Dev

How to parse MySQL config file my.cnf using parse_ini_file()

From Dev

How to get nested value from option that are in config.ini file using python

From Dev

Align values in an INI file generated using ConfigParser

From Dev

How to open an ini config file from filename stored in another ini config file?

From Dev

How to open an ini config file from filename stored in another ini config file?

From Dev

Connect to Access database using C# Web.config file

From Dev

Change HTML text by URL using *.ini config file

From Dev

How do I modify config file at runtime

From Dev

C++ How do I access and modify an array with using []?

From Dev

Access property values inside Spring config file

From Dev

Using submit() replaces space values with “+” and "," with "%252C" how to modify?

From Dev

How to read multiple values in C# app.config file?

From Dev

How to read multiple values in C# app.config file?

From Dev

how can I turn config ini file into system environment in bash?

From Dev

How to Handle Special character in config.ini file as variable in php

From Dev

how can I turn config ini file into system environment in bash?

From Dev

How to put a 2 array variables in config (.ini) file?

From Dev

how to read connection string in config.ini file

From Dev

Writing values to INI file

From Dev

Modify keyboard config file

From Dev

modify KMail config file

From Dev

Modify keyboard config file

From Dev

Using INI file to fill setup section values on inno setup

From Java

How to access and modify a SSH file on mac?

From Dev

How get config file values in other config file - Laravel 5

From Dev

C using open()read()write() to access text modify it and store in a new file

From Dev

How can I access a custom section in a Pyramid .ini file?

From Dev

Using Config::Simple to read MySQL config file with keys without values

Related Related

  1. 1

    How to modify .INI file with using sharpconfig?

  2. 2

    How to parse MySQL config file my.cnf using parse_ini_file()

  3. 3

    How to get nested value from option that are in config.ini file using python

  4. 4

    Align values in an INI file generated using ConfigParser

  5. 5

    How to open an ini config file from filename stored in another ini config file?

  6. 6

    How to open an ini config file from filename stored in another ini config file?

  7. 7

    Connect to Access database using C# Web.config file

  8. 8

    Change HTML text by URL using *.ini config file

  9. 9

    How do I modify config file at runtime

  10. 10

    C++ How do I access and modify an array with using []?

  11. 11

    Access property values inside Spring config file

  12. 12

    Using submit() replaces space values with “+” and "," with "%252C" how to modify?

  13. 13

    How to read multiple values in C# app.config file?

  14. 14

    How to read multiple values in C# app.config file?

  15. 15

    how can I turn config ini file into system environment in bash?

  16. 16

    How to Handle Special character in config.ini file as variable in php

  17. 17

    how can I turn config ini file into system environment in bash?

  18. 18

    How to put a 2 array variables in config (.ini) file?

  19. 19

    how to read connection string in config.ini file

  20. 20

    Writing values to INI file

  21. 21

    Modify keyboard config file

  22. 22

    modify KMail config file

  23. 23

    Modify keyboard config file

  24. 24

    Using INI file to fill setup section values on inno setup

  25. 25

    How to access and modify a SSH file on mac?

  26. 26

    How get config file values in other config file - Laravel 5

  27. 27

    C using open()read()write() to access text modify it and store in a new file

  28. 28

    How can I access a custom section in a Pyramid .ini file?

  29. 29

    Using Config::Simple to read MySQL config file with keys without values

HotTag

Archive