惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
B
Blog RSS Feed
I
InfoQ
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏

博客园 - 毛毛亟亟

ectouch 微信支付成功后订单状态未改变的解决办法 (转载) SQLSERVER2008以上版本的数据恢复 windows 2012(64位) IIS配置asp程序 500 - 内部服务器错误。您查找的资源存在问题,因而无法显示。 终于遇到了传说的ie 6 img 3px的bug This template requires a more recent version of the Android Eclipse plugin. Please update from versi This Android SDK requires Android Developer Toolkit version 20.0.0 or above CodeSmith Professional 5与VS2010有冲突 VS2005调试无法进入断点,暂停、停止、重编按钮为灰色 VS2005重置所有设置 flex 3中FileReference无法使用save()的问题 无法为区域设置“en_US”解析资源束“ViewerStrings” flexbuilder安装格式化组件和VSS组件 从旗舰版VS2010到部署完善MVC4成功,流程记录 sqlserver 2005与sqlserver2008的日志清理 [转载]如何学习Flex Framework Flex String JSON 转换成 ArrayCollection 使用VS2010开发服务端程序时每次安装服务名都是service1 extjs中grid的单击行或者双击行事件 获取Extjs中的TreePanel中所有的被checked的叶子节点的id
.net读取ini配置文件的操作
毛毛亟亟 · 2012-08-14 · via 博客园 - 毛毛亟亟

.net读取ini配置文件的操作

#region 读取和写入ini文件的操作

        
        string inipath = System.Windows.Forms.Application.StartupPath + @"\config.ini";
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        /// <summary>
        
/// 读取配置ini文件
        
/// </summary>
        
/// <param name="Section">配置段</param>
        
/// <param name="Key"></param>
        
/// <param name="innpath">存放物理路径</param>
        
/// <returns></returns>
        public string IniReadValue(string Section, string Key, string innpath)
        {
            StringBuilder temp = new StringBuilder(500);
            GetPrivateProfileString(Section, Key, "", temp, 500, inipath);
            return temp.ToString();
        }
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        /// <summary>
        
/// 写入ini文件的操作
        
/// </summary>
        
/// <param name="Section">配置段</param>
        
/// <param name="Key"></param>
        
/// <param name="Value">键值</param>
        
/// <param name="inipath">物理路径</param>
        public void IniWriteValue(string Section, string Key, string Value,string inipath)
        {
            WritePrivateProfileString(Section, Key, Value, inipath);
        }
         #endregion

要注意的是[DllImport("kernel32")]必须要放在静态方法之前,而且不能偷懒是读和写都有一次引用。