110,535
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 获取配置文件中某个Key的值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetConfigValue(string key)
{
try
{
System.IO.FileInfo finfo = new System.IO.FileInfo(System.Reflection.Assembly.GetCallingAssembly().Location);
string path = finfo.DirectoryName + "\\config.ini";
if (!System.IO.File.Exists(path))
{
using (System.IO.File.Create(path))
{
}
}
using (System.IO.StreamReader sr = new System.IO.StreamReader(path))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine().Trim();
if (line.StartsWith(key))
{
return line.Replace(key + "=", "");
}
}
}
}
catch (Exception ex)
{
}
return "";
}