System config file com




















The following code retrieves the value for the Key0 attribute from the associated configuration file. The code then places this value in the sAttr string variable. If a key doesn't exist for this value, nothing is stored in sAttr. To display the value that the application retrieves in the Console window, use Console. WriteLine as follows:. These pairs are stored in a NameValueCollection type. The NameValueCollection class is in the System. Specialized namespace. The AllKeys property of NameValueCollection references a string array that has an entry for each key that the application retrieves.

Use a foreach construction to iterate through the AllKeys array to access each key that the application retrieves. Each key entry in AllKeys is a string data type. Inside the foreach construction, use Console. WriteLine to display the key and its associated value in the Console window.

The current key that the application processes is in s. Use it as an index in the sAllNameValueCollection to obtain its associated value.

This code is targeting the. NET Framework 2. If you are using the. NET Framework 1. Press F5 to run the code. The configuration file is saved in XML format. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. What is the use system. Ask Question. Asked 4 years, 9 months ago. Active 3 years, 8 months ago. Viewed 8k times. Manush Manush 1, 5 5 gold badges 19 19 silver badges 32 32 bronze badges. Add a comment. Active Oldest Votes. Edit forgot to explain config. Bean Bean 1, 2 2 gold badges 13 13 silver badges 35 35 bronze badges. Sajeetharan Sajeetharan k 55 55 gold badges silver badges bronze badges.

If your application needs read-only access to its own configuration, it is recommended that you use the GetSection method overloads for Web applications.

For client application, use the GetSection String method. These methods provide access to the cached configuration values for the current application, which has better performance than the Configuration class.

Note: If you use a static GetSection method that takes a path parameter, the path parameter must refer to the application in which the code is running, otherwise the parameter is ignored and configuration information for the currently running application is returned.

You use one of the Save methods to write configuration information. Note that the user or process that writes must have the following permissions:. Write permission on the configuration file and directory at the current configuration hierarchy level. Gets the AppSettingsSection object configuration section that applies to this Configuration object.

Gets a ConnectionStringsSection configuration-section object that applies to this Configuration object. Gets the ContextInformation object for the Configuration object. Gets the physical path to the configuration file represented by this Configuration object. Gets a value that indicates whether a file exists for the resource represented by this Configuration object.

Gets the locations defined within this Configuration object. Gets the root ConfigurationSectionGroup for this Configuration object. Gets a collection of the sections defined by this Configuration object. Gets or sets the targeted version of. NET when a version earlier than the current one is targeted. Returns the specified ConfigurationSection object.

Gets the specified ConfigurationSectionGroup object. Gets the Type of the current instance. Creates a shallow copy of the current Object. Writes the configuration settings contained within this Configuration object to the current XML configuration file.

Writes the configuration settings contained within this Configuration object to the specified XML configuration file. Skip to main content. This browser is no longer supported.



0コメント

  • 1000 / 1000