views:

60

answers:

2

I am reading excel file and for that I do have connection string in App.config but I want to read each day the excel which is today's excel..

Each excel name is today's date(MM/dd/yy), so datasource name is somewhat dynamic. how to write the connection string in App.Config then

I want to use something like

<add name="Excels" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\[Today'sDate].xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=0';" />

I am using windows app in VS

+1  A: 

If you don't want a static value, don't put it in app.config :) Or rather, put a template in app.config, but when you create the actual data source, perform a template replacement before you create the connection. Presumably you are creating the connection yourself, so you can get in there to change the connection string?

Jon Skeet
+1  A: 
ConfigurationManager.ConnectionStrings["Excels"].ConnectionString.Replace("[Today'sDate]", DateTime.Today.ToString("fmt"))

Connection string is just string ;)

gandjustas