using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.Text; namespace File_IO
{ public class inifile
{
public string Path;
public string Section;
public string Key;
public string value;
public inifile(string path)
{
this.Path=path;
}
#region 声明读写INI的API函数
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
#endregion

C#代码实现如下

 public void openorcreat()
{
if (File.Exists(Path))
{
}
else
{
File.Create(Path);
}
}

C#代码实现

public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(); int i = GetPrivateProfileString(Section, Key, "", temp, , this.Path);
return temp.ToString();
}
public string IniReadValue()
{
return IniReadValue(Section, Key);
}

c#代码实现

 public void IniWriteValue()
{
IniWriteValue(Section, Key, value);
}
public void IniWriteValue(string Section, string Key, string value)
{
WritePrivateProfileString(Section, Key, value, this.Path);
}

C#代码实现

 public void removeKey(string Section, string Key)
{
IniWriteValue(Section, Key, null);
}

C#代码实现

public string[] GetKeyNames(string Section)
{
byte[] allKeys = IniReadValues(Section, null);
string[] keylist;
string keynames;
ASCIIEncoding scii = new ASCIIEncoding();
keynames = scii.GetString(allKeys);
keylist = keynames.Split(new char[] { '\0' });
return keylist;
}

C#实现

public string[] GetSectionNames()
{
byte[] allSection = IniReadValues(null, null);
string[] sectionList;
string sections;
ASCIIEncoding ascii = new ASCIIEncoding();
sections = ascii.GetString(allSection);
sectionList = sections.Split(new char[] { '\0' });
return sectionList;
}

C#代码实现

public void removeSection(string Section)
{
IniWriteValue(Section, null, null);
}

  

【LABVIEW到C#】1》ini的操作的更多相关文章

  1. LabVIEW之生产者/消费者模式--队列操作 彭会锋

    LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...

  2. ini文件操作

    Config.ini 文件操作 [SYS] sysname=hy company=hyhy tel=2 using System; using System.Collections.Generic; ...

  3. ini 文件操作记要(1): 使用 TIniFile

    ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Class ...

  4. winform INI文件操作辅助类

    using System;using System.Runtime.InteropServices;using System.Text; namespace connectCMCC.Utils{ // ...

  5. Ini文件操作类

    /// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...

  6. LabVIEW之生产者/消费者模式--队列操作

    LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...

  7. python基础——15(加密、excel操作、ini文件操作、xml操作模块及数据格式分类)

    一.加密模块 1.有解密的加密方式(base64) #base64加密 import base64 str_encrypt = input("输入要加密的字符串:\n") base ...

  8. C# ini配置文件操作类

    /// <summary> /// INI文件操作类 /// </summary> public class IniFileHelper { /// <summary&g ...

  9. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

随机推荐

  1. MiniUI 在线示例

    引用 http://miniui.com/demo/#src=datagrid/celledit.html

  2. java 抽象类实现接口

    1.抽象类肯定可以实现接口:  2.这不是有没有意义的事情,是一种思想,当你自己写的类想用接口中个别方法的时候(注意不是所有的方法),那么你就可以用一个抽象类先实现这个接口(方法体中为空),然后再用你 ...

  3. [转载]Spring中MultipartHttpServletRequest实现文件上传

    实现图片上传  用户必须能够上传图片,因此需要文件上传的功能.比较常见的文件上传组件有Commons FileUpload(http://jakarta.apache.org/commons/file ...

  4. IDEA创建Tomcat8源码工程流程

    上一篇文章的产出,其实离不开网上各位大神们的辅助,正是通过他们的讲解,我才对Tomcat的结构有了更进一步的认识. 但在描述前后端交互的过程中,还有很多细节并没有描述到位,所以就有了研究Tomcat源 ...

  5. C语言转义字符的使用方法

    cppreference.com -> 转义字符 常量转义字符 以下的转义字符使普通字符表示不同的意义. 转义字符 描述 \' 单引号 \" 双引号 \\ 反斜杠 \0 空字符 \a ...

  6. 20160419 while练习,复习

    10 一.while和if题目练习 . 二.知识拓展 1. C#中的委托是什么?事件是不是一种委托? 答 :    委托可以把一个方法作为参数代入另一个方法.委托可以理解为指向一个函数的引用.     ...

  7. 转:USB枚举

  8. mongodb php 支持

    http://bbs.csdn.net/topics/391931404?page=1 windows下为php7.0.4安装目前官方版本对应的最新的php_mongodb.dll扩展,该扩展版本为1 ...

  9. 快乐学习 Ionic Framework+PhoneGap 手册1-2{介绍Header,Content,Footer的使用}

    *先运行第一个简单的APP,介绍Header,Content,Footer的使用 {2.1}运行一个简单的APP,效果如下 {2.2}Header代码 <ion-header-bar class ...

  10. java.lang.NullPointerException报错的几种情况

    java.lang.NullPointerException报错的几种情况: 1.字符串变量未初始化: 2.接口类型的对象没有用具体的类初始化,比如: List stuList :这种情况就会报空指针 ...