Question

I am using sharpconfig for Load my .INI file. i got success in reading ini file and its very user friendly.

 Dim config As New SharpConfig.Configuration
 config = SharpConfig.Configuration.Load("D:\Myini.ini")

Now i want to replace particular word of .ini file. SharpConfig showing that its also providing the .INI file modify functionality but i can not able to find how i can modify my file with sharpconfig

Please help me. Thanks!

Was it helpful?

Solution

Given an INI file that looks like this:

[MySection]
MySetting = 123

You read it with SharpConfig.Configuration.Load:

Dim yourpath = "c:\WhatEver.ini"
Dim config = SharpConfig.Configuration.Load(yourpath)
Console.WriteLine(config("MySection")("MySetting").Value)

This code will print

123

Now, to change the INI file, simply assign a new value and save it like:

config("MySection")("MySetting").Value = "Foobar"
config.Save(yourpath)

The INI file will now look like this:

[MySection]
MySetting = Foobar

OTHER TIPS

You already refered to the codeplex page and there you can even find a a test app that shows how to do stuff with it: TestApp

If you have the Category and the Setting you can get/set the value of the Setting with .Value

In the Sourcecode of SharpConfig it is easy readable what can be accessed. I'm a VB guy myself but it should be no problem to read the c# stuff >> Settings

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top