Link to home
Create AccountLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

I need to write a console app Batch process using App Config

I need to write a console app Batch process using App Config


I need to use App Config to:

1) Read Source and Target folders

2) Import all filenames from Source folder

3) Iterate through each file in the folder

4) Make a decision about which ONE of four or five target folders match

5) Move the file to the unique Target folder


This batch will run every 5-minutes, or so.


Suggestions on this process? 


Filename make be in two parts:

BOL-xxxx


Bill of Lading + Key


Please make suggestions.


Thanks


Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

How exactly is this decision made, which file goes in which target folder?! Mapping?! RegEx?! etc...

Avatar of curiouswebster

ASKER

It is now completed, but I am mocking some values here:
            // read all Keys from the App Settings
            Dictionary<string, string> filenameKeys = new Dictionary<string, string>() {
                { "Key1", "C:\\MyFolder\\SamplePdfFolderTarget1" },
                { "Key2", "C:\\MyFolder\\SamplePdfFolderTarget2" },
                { "Key3", "C:\\MyFolder\\SamplePdfFolderTarget3" }};

What is the code to read into a Dictionary from AppSettings?

Thanks
SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I have that already, but wanted to fill the Dictionary from Key/Value pairs in the App Settings.

Ok, my bad :-(

So, you already have your AppConfig "ready" then? Could you provide it?

ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account

Given App.config be like

<?xml version="1.0" encoding="utf-8"?>
<configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /> </startup> <appSettings> <add key="Key1" value="C:\\MyFolder\\SamplePdfFolderTarget1"/> <add key="Key2" value="C:\\MyFolder\\SamplePdfFolderTarget2"/> <add key="Key3" value="C:\\MyFolder\\SamplePdfFolderTarget3"/> </appSettings> </configuratio

Open in new window

... you could iterate over those keys like:

            foreach(string key in ConfigurationManager.AppSettings)
           { Debug.WriteLine(key + " = " + ConfigurationManager.AppSettings[key]);            }        

Open in new window