4

I am writing a program that will be running continually on a server. I would like to be able to change some of the inputs without hard coding requiring recompiling.

I know this is possible to do by using a text file, however I don't want to have a text file for each value.

I also know that I could use a table, but I also don't want to have a table with one row for this program.

Is there another solution?

As you can probably guess, I am new to the .NET/C# world, so pardon if this is too basic of a question.

1
  • 5
    using Application Configuration files (app.config).
    – YavgenyP
    Oct 5, 2012 at 18:01

5 Answers 5

7

Use the appsettings section of the app.config.

2
  • 1
    Related question: Is getting information from a config file faster, less resource intense ect, then reading plain text data in from a .txt? I am assuming yes.
    – Mason240
    Oct 5, 2012 at 19:31
  • 1
    @Mason - Each method is fast enough not to worry about. The config file may theoretically be slower initially because it is parsing XML, but usually a c# app already has a config file, so in that case using it is free. Oct 5, 2012 at 19:56
4

Depending on what you are trying to accomplish, Application Settings may also serve your needs. These are stored on the client computer. You can save user settings here, for example.

My preference is most cases is App.config (Web.config in ASP.NET), though, as has been suggested by other replies.

3

It sounds like you need one or more Config files, C# has built in support for an XML formatted Config File App.Config the access point to which lives in System.Configuration.ConfigurationManger.AppSettings

3

You have many possibilities:

  • Text file with separated values
  • XML file with element values
  • Web.config if your program is ASP.NET
  • App.config
  • Database (But not in your case)
  • Web Service from another program to (Maybe overkill)
  • Hard coded values in html (non compiled file)

The easiest is Web.config or App.config because .net have already tools for you when you want those values : ConfigurationSettings.AppSettings["Key"];

0
2

Not really clear what are you trying to acomplish but if i understood well you want a value in your program to change dynamically. If thats the case you can use xml configuration the XmlReader and XmlWriter class in the System.Xml namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.