C# loop through app.config but only use keys like "service" -
I am currently receiving a server name through a test file and checking the status of a specific service and if It is turned off It works perfectly with my service names stored in my app.config What I want to do is also store my file path, file name, timeout and any other key that I Put in the app. Under the configured road My problem is that when I was looping through app.config, I have only service names that work perfectly. If I add other keys that I want to add then I will definitely get "no service", how do I raise the "service" key just like "?" I am naming the key "service1", 2, 3, etc.
foreach (string key in ConfigurationManager.AppSettings) {string value = ConfigurationManager.AppSettings [key]; // Create an example of StreamReader to read from a file. // The statement of usage also closes the streamminder (using the Streamer sr = new streamrider (txtFilePath + txtFile)) {string line; // Read the lines from the file and display until the file ends up to 1 /. While ((line = sr.ReadLine ()) = null) {Console.WriteLine (line); // Check lines with semi-colon if the line on // half of the colon starts leaving it (line. StartsWith (";")) {continue; } Other {ServiceController sc = New Service Controller (Value, Line); // Create new timeout module TimeSpain Timeout = New TimeSpain (); // Console for the current service status console. Light line ("" + value + "service status is currently set to {0}", sc.Status.ToString ()); You should go to a named configuration section with elements that you use AppSetting Kar VS collection.
I follow the recommendations for creating a custom section in your config file, and then you are not searching for items based on the key, but
Comments
Post a Comment