0

My requirement is to have multiple jobs and I have to loop through the JobName's of all jobs to check whether it exists currently.

    <configuration>
      <Job>
       <appSettings>
        <add key="JobName" value="BigDataUpload" />
       </appSettings>
      </Job>
      <Job>
       <appSettings>
        <add key="JobName" value="QueryUpload" />
       </appSettings>
      </Job>
    </configuration>

I am not sure whether this facility is present in C#. Currently I have one AppSettings inside Configuration and I access it using ConfigurationManager.AppSettings.Get("JobName").

Any help is appreciated !!

user3447653
  • 3,968
  • 12
  • 58
  • 100
  • 1
    http://stackoverflow.com/questions/11351106/multiple-appsettings-files-is-it-possible you should understand how the `App.config || Web.Config` sections work you can only have 1 `` – MethodMan May 03 '16 at 20:19
  • appSettings only supports key/value pairs as strings. If you need to store multiple values for a key like JobNames, store the values as a comma-seperated list like – Jon May 03 '16 at 20:29

1 Answers1

0

I don't thing that can be done, but you can use:

<configuration>
    <appSettings>
        <add key="JobName1" value="Job1" />
        <add key="JobName2" value="Job2" />
        ...
        <add key="JobName(n)" value="Job3" />
    </appSettings>
</configuration> 

And then you can use a loop to load them until they're null:

int jobNumber = 1;
string lastJob = null;
do
{
    jobNumber++;
    lastJob = ConfigurationManager.AppSettings["JobName" + jobNumber];

    if(lastJob != null)
        //process the job name

}while(lastJob != null);
Gusman
  • 14,905
  • 2
  • 34
  • 50