I have a console based application which pulls files from a database and outputs them onto the C drive. It also outputs an excel file with the details of all outputted files. Here is the snippet of code from the 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 the program runs, I would like the excel file to be named with the date appended onto the end of it. Is there any way I can achieve this in the app.config file?
Also, here is the class that relating to the 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 { get { return (string)this[messageName]; } }
[ConfigurationProperty("fileName", IsRequired = true)]
public string FileName { get { return (string)this[fileName]; } }
}
Any help would be appreciated, thanks guys.
EDIT
Have edited my code to the following
[ConfigurationProperty("fileName", IsRequired = true)]
public string FileName = string.Format(MetadataEncoderElement.fileName, DateTime.Now);
However now I have the following errors:
The best overloaded method match
for’string.Format(System.IFormatProvider,
string, params object[])’ has some
invalid argumentsArgument 1: cannot convert from’System.Configuration.ConfigurationProperty’
to ‘System.IFormatProvider’Argument 2: cannot convert from ‘System.DateTime’ to ‘string’
Slightly improved version of Richards answer:
in the code
EDIT:
If you want to build it in your Property you can do it this way: