我爱Aspx >> XML/XLST >> Upgrade Your INI Files to XML with .NET (3)
| |
|
Updating and Adding Items
Updating individual values is similar to retrieving them. You provide a section name, a key name, and the new value. The class uses the GetItem method to locate the appropriate <item> element, and then updates that item's value attribute with the specified new value. The Windows API function WritePrivateProfileString creates new sections and items if you call it with a section or key name that doesn't already exist. Although it's not good object-oriented design, for consistency the IniFileReader class acts identically, meaning that you can create a new section simply by passing a nonexistent section name. To update a section name, key name, or value for existing sections or items, select the section and item you want to update, enter the new values in the appropriate fields, and then click the Update button to apply the changes. To create a new section or key on the sample form, first click the New Section or New Key button to clear the current selections, and then enter the new section or key name and click the Update button to apply your changes. To delete a section using the API, you pass the section name and a null key value to the WritePrivateProfileString function—and you do the same with the IniFileReader class, except that you use the SetIniValue method. For example, the following code would delete the section named section1. 【我对这篇文章有话说?】下一篇:XML在.net平台下的自定义控件的应用
|