C#——读写ini文件
2016-07-20 11:26
429 查看
namespace JF_SJ.Services
{
public class InIWriteAndRead
{
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
public static void INIWrite(string section, string key, string value, string sPath)
{
// section=配置节,key=键名,value=键值,path=路径
WritePrivateProfileString(section, key, value, sPath);
}
public static string INIReade(string section, string key, string sPath)
{
// 每次从ini中读取多少字节
System.Text.StringBuilder temp = new System.Text.StringBuilder(255);
// section=配置节,key=键名,temp=上面,path=路径
GetPrivateProfileString(section, key, "", temp, 255, sPath);
return temp.ToString();
}
}
}
{
public class InIWriteAndRead
{
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
public static void INIWrite(string section, string key, string value, string sPath)
{
// section=配置节,key=键名,value=键值,path=路径
WritePrivateProfileString(section, key, value, sPath);
}
public static string INIReade(string section, string key, string sPath)
{
// 每次从ini中读取多少字节
System.Text.StringBuilder temp = new System.Text.StringBuilder(255);
// section=配置节,key=键名,temp=上面,path=路径
GetPrivateProfileString(section, key, "", temp, 255, sPath);
return temp.ToString();
}
}
}
相关文章推荐
- C# 使用 CancellationTokenSource 终止线程
- C# ListView用法详解
- c#——Winform PropertyGrid使用(二)
- Xamarin学习:点按按钮累加次数并显示
- C# 根据身份证号码获取简易信息
- C#基础-3:委托(Delegate)
- dev gridview显示行号
- [c#]获取exchange中的图片
- C#中压缩/解压缩7-zip文件的方法
- C# 发送邮件 附件名称为空
- 参数数组和普通数组
- C#写的邮箱发送程序源代码
- c# - 反序列化报错:Input string was not in a correct format
- C# 枚举的使用
- C# 正则表达式的使用
- C#生成二维码名片
- C#生成二维码名片
- C#的 第6节课
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解