Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I am trying to create a program, I am a little newbie. What I want to do is the following, I have a search button to select the folder where the .ini file I want to work with is located, now I also have a textbox that is the one that I want the data to be put there to change in a specific line of a specific .ini file that I indicate, to look inside that previously selected folder ... If I make myself understood, I hope you can help me with some code or at least how to find this information.

What I have tried:

I was looking for information and I read something about app.config can it be?
Posted
Updated 17-Sep-21 7:07am
Comments
Dave Kreskowiak 13-Sep-21 8:10am    
What's the difference between your app and, say, Notepad?

You may either use (as already suggested) the C# file I/O facilities and write you own INI parser (the INI format is very simple) or you may use one of the many available libraries you find on the web (see, for instance GitHub - rickyah/ini-parser: Read/Write an INI file the easy way![^]).
 
Share this answer
 
This is a class that I wrote when I needed to read an INI file from the system. You'll need to add the method to invoke WritePrivateProfileString( )

public class IniFile
{
	private readonly string _inifile;

	[DllImport("kernel32", CharSet = CharSet.Unicode)]
	private static extern int GetPrivateProfileString(string section, string key,
		string defaultValue, StringBuilder value, int valueSize, string filepath );

	public IniFile( string inifile )
	{
		_inifile = new FileInfo( inifile ).FullName;
	}

	public string Read( string section, string key )
	{
		var value = new StringBuilder(255);
		GetPrivateProfileString( section, key, "", value, 255, _inifile );
		return value.ToString();
	}

	public bool KeyExists(string section, string key )
	{
		return Read(section, key ).Length > 0;
	}
}
 
Share this answer
 
Try to read File, Directory class and how to read/write Text file with c#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900