-1

A simple file moving console application where source path and destination path is hard coded right now. I have to run this application in different environment - testing and production with different source path and destination path. how to set those path for copying or moving files. how to code or call those path from config files in program.cs

learningMonk
  • 1,101
  • 13
  • 34

1 Answers1

0

source path and destination path is hard coded right now

Move them to config values. Making use of App.config for environment-specific values is exactly what config files are for. Something as simple as:

<appSettings>
  <add key="BasePath" value="C:\some\path\" />
</appSettings>

In the code you'd get that value from the System.Configuration assembly. Something like:

var basePath = ConfigurationManager.AppSettings["BasePath"];

(Include any error checking you require to make sure it's a valid path, etc.)

Then when you need to create the full path, you'd include that value when combining with other known values, such as non-changing parts of the path or file names or whatever information you have. Something like:

var sourcePath = Path.Combine(basePath, "/some/middle/part", fileName);

You can then use File operations on sourcePath.

Each environment would have its own App.config file.

David
  • 208,112
  • 36
  • 198
  • 279