| |

VerySource

 Forgot password?
 Register
Search
View: 586|Reply: 3

Is there a function to directly read the ini file in c #?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-28 16:00:02
| Show all posts |Read mode
Is there a function to directly read the ini file in c #?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-24 17:00:01
| Show all posts
Read one write
[DllImport ("kernel32")]
private static extern long WritePrivateProfileString (string section, string key, string val, string filePath);
[DllImport ("kernel32")]
private static extern int GetPrivateProfileString (string section, string key, string def, StringBuilder retVal, int size, string filePath);
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-3-25 15:45:01
| Show all posts
A class to read and write INI:
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Ini
{
public class IniFile
{
 
public string path;
 
[DllImport ("kernel32")]
private static extern long WritePrivateProfileString (string section, string key, string val, string filePath);
 
[DllImport ("kernel32")]
private static extern int GetPrivateProfileString (string section, string key, string def, StringBuilder retVal, int size, string filePath);

public IniFile (string INIPath)
{
path = INIPath;
}
public void IniWritevalue (string Section, string Key, string value)
{
WritePrivateProfileString (Section, Key, value, this.path);
}
public string IniReadvalue (string Section, string Key)
{
StringBuilder temp = new StringBuilder (255);
 
int i = GetPrivateProfileString (Section, Key, "", temp, 255, this.path);
return temp.ToString ();
}
}
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-29 12:30:02
| Show all posts
Thank you!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list