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
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.
Comments