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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 毛毛亟亟

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")]必须要放在静态方法之前,而且不能偷懒是读和写都有一次引用。