1

I think this will be a simple question. I have an App.config that contains a path

<appSettings>
  <add key="Path" value="C:\\Test\\" />
</appSettings>

I want to add a couple more paths to the App.config so I don't have them hard coded in my C# windows service. Will it work if I change this

string newPath = @"C:\SecondTest\" + fileName;

to this

string newPath = ConfigurationManager.AppSettings["SecondPath"] + fileName;

I could then create SecondPath in the App.config.

3 Answers 3

2

Yes, it will work but it would be better to combine paths like this instead of using string concatenations:

string newPath = Path.Combine(
    ConfigurationManager.AppSettings["SecondPath"], 
    fileName
);
Sign up to request clarification or add additional context in comments.

Comments

0

Yes that would work (did you try it ?).

Comments

0

AppSettings works like key-value storage so it will work however you like

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.