c# - Dynamically insert date into App.Config -


i have console based application pulls files database , outputs them onto c drive. outputs excel file details of outputted files. here snippet of code app.config file.

  <target name="group1" acceptedfiletypes="pdf">     <ftpsettings server="localhost" username="anonymous" password="user@user.com" />     <metadataencoder name="group1" filename="group1_yyyymmdd.xls" />   </target> 

ideally, when program runs, excel file named date appended onto end of it. there way can achieve in app.config file?

also, here class relating above app.config snippet:

public class metadataencoderelement : configurationelement {     private static readonly configurationproperty messagename = new configurationproperty("name", typeof(string), string.empty, configurationpropertyoptions.isrequired);     private static readonly configurationproperty filename = new configurationproperty("filename", typeof(string), string.empty, configurationpropertyoptions.isrequired);      public metadataencoderelement()     {         this.properties.add(messagename);     }      [configurationproperty("name", isrequired = true)]     public string name { { return (string)this[messagename]; } }      [configurationproperty("filename", isrequired = true)]     public string filename { { return (string)this[filename]; } } } 

any appreciated, guys.

edit

have edited code following

[configurationproperty("filename", isrequired = true)] public string filename = string.format(metadataencoderelement.filename, datetime.now); 

however have following errors:

the best overloaded method match for'string.format(system.iformatprovider, string, params object[])' has invalid arguments

argument 1: cannot convert from'system.configuration.configurationproperty' 'system.iformatprovider'

argument 2: cannot convert 'system.datetime' 'string'

slightly improved version of richards answer:

<metadataencoder name="group1" filename="group1_{0:yyyymmdd}.xls" /> 

in code

string filename = string.format(yourconfig.filename,datetime.now); 

edit: if want build in property can way:

[configurationproperty("filename", isrequired = true)] public string filename { { return string.format((string)this[filename], datetime.now); } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -