日期:2014-05-17 浏览次数:21001 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
namespace ConsoleApplicationCsdn
{
class Program
{
static void Main(string[] args)
{
string A = OperateIniFile.ReadIniData("Section1", "A", "", @"C:\Users\myx\Desktop\Excel.ini");
//姓名
}
}
public class OperateIniFile
{
#region API函数声明
[DllImport("kernel32")]//返回0表示失败,非0为成功
private static extern long WritePrivateProfileString(string section,string key,
string val,string filePath);
[DllImport("kernel32")]//返回取得字符串缓冲区的长度
private static extern long GetPrivateProfileString(string section,string key,
string def,StringBuilder retVal,int size,string filePath);
#endregion
#region 读Ini文件
public static string ReadIniData(string Section,string Key,string NoText,string iniFilePath)
{
if(File.Exists(iniFilePath))
{
StringBuilder temp = new StringBuilder(1024);