public class INIUserAccound
{ static IniFile Ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + @"\Config\User.Ini"); const string Session = "UserInfo";
/// <summary>
/// 获得用户名
/// </summary>
/// <returns></returns>
public static string GetAccound()
{
return Ini.IniReadValue(Session, "Accound");
}
/// <summary>
/// 保存用户名
/// </summary>
/// <param name="SkinName"></param>
public static void SetAccound(string Accound)
{
Ini.IniWriteValue(Session, "Accound", Accound);
} /// <summary>
/// 获得密码
/// </summary>
/// <returns></returns>
public static string GetPwd()
{
return Ini.IniReadValue(Session, "Pwd");
}
/// <summary>
/// 保存密码
/// </summary>
/// <param name="SkinName"></param>
public static void SetPwd(string Pwd)
{
Ini.IniWriteValue(Session, "Pwd", Pwd);
} }
 /// <summary>
/// 操作INI文件类 测试信息
/// </summary>
public class IniFile
{
const int DATA_SIZE = 1024; private string _path; //INI档 案 名
public string IniPath { get { return _path; } set { _path = value; } } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct STRINGBUFFER
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = DATA_SIZE)]
public string szText;
} //读写INI文件的API函数
[DllImport("kernel32", CharSet = CharSet.Auto)]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32", CharSet = CharSet.Auto)]
private static extern int GetPrivateProfileString(string section, string key, string def, out STRINGBUFFER retVal, int size, string filePath); //类的构造函数,传递INI档案名
public IniFile(string sPath)
{
_path = sPath;
string path = IniPath.Substring(0, IniPath.LastIndexOf("\\"));
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
if (!File.Exists(_path)) CreateIniFile();
} //写INI文件
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this._path);
} //读取INI文件指定项目的数据
public string IniReadValue(string Section, string Key)
{
int i;
STRINGBUFFER RetVal;
i = GetPrivateProfileString(Section, Key, null, out RetVal, DATA_SIZE, this._path);
string temp = RetVal.szText;
return temp.Trim();
} //读取INI文件指定项目的数据
public string IniReadValue(string Section, string Key, string defaultValue)
{
int i;
STRINGBUFFER RetVal;
i = GetPrivateProfileString(Section, Key, null, out RetVal, DATA_SIZE, this._path);
string temp = RetVal.szText;
return temp.Trim() == "" ? defaultValue : temp.Trim();
} /// <summary>
/// 创建INI文件
/// </summary>
public void CreateIniFile()
{
StreamWriter w = File.CreateText(_path);
w.Write("");
w.Flush();
w.Close();
}
}

最新文章

  1. Membership三步曲之进阶篇 - 深入剖析Provider Model
  2. JS 中 Array.slice() 和 Array.splice()方法
  3. sqlserver临时表操作
  4. ubuntu删除软件命令
  5. Linux删除文件夹命令
  6. Telnet连接Win7系统被拒绝的原因及解决方法
  7. git 添加忽略文件
  8. [置顶] android 自定义圆角ImageView以及锯齿的处理
  9. 57. Spring 自定义properties升级篇【从零开始学Spring Boot】
  10. C#开发学习——web服务器端控件
  11. Linux 性能搜集【linux_reports-cpu/memory/disks/network】
  12. [2017-7-28]Android Learning Day7
  13. loadrunner笔记(三):设置、运行场景和生成测试报告
  14. 在 Linux 上使用 VirtualBox 的命令行管理界面
  15. (转)每天一个linux命令(21):find命令之xargs
  16. angular指令中使用ngModelController
  17. [C++ Primer] 第3章: 字符串, 向量和数组
  18. Android 编辑框插入表情图片
  19. ios retainCount
  20. 改变Fragment的默认动画

热门文章

  1. SQLServer出现 &#39;其他会话正在使用事务的上下文&#39; 的问题原因,什么是环回链接服务器?(转载)
  2. 四种MySQL存储引擎
  3. (顺序表的应用5.4.2)POJ 1591 M*A*S*H(约瑟夫环问题的变形——变换步长值)
  4. android 项目学习随笔五(JSON解析)
  5. codereview
  6. Apache服务器访问过慢分析及解决
  7. Atom Remote-FTP connecting FTP with SSL/TLS
  8. 时间戳转换成Date
  9. php number_format()保留小数点后几位
  10. linux命令:du 命令