Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative paths in web.config 1

Status
Not open for further replies.

mclosson

Programmer
Mar 19, 2001
24
CA
Does anyone know of a way to include a relative path reference in web.config?

For example, I would like to store an access database connection string in web.config. I would like to set the Data Source parameter to the metadb.mdb file in the web application root. However, for reusability reasons, I would like to avoid specifying the entire file path in web.config.


Any suggestions would be greatly appreciated. Thank you.

Mike
 
"Data Source=" & Server.MapPath("fpdb\Sites.mdb;"))

..using MapPath

Mike - there have been a few discussions on saving connection strings in the Global file here at Tek-tips - you might want to do a quick search.
 
From what I can see, the MapPath function does not work in the web.config file. I was wondering if there is any way to do something similar to MapPath withing the web.config file itself.

Mike
 
There is no equivalent to MapPath in web.config as this file is neither compiled nor parsed. Probably the easiest way to do this is to have your provider string in the web.config with a marker for the full path and then do a replace on this when you use it something like..

web.config
"Data Source=fullpath/metadb.mdb"

code
= ConfigurationSettings.AppSettings["provider_key_name"].Replace("fullpath", Server.MapPath("/"));

I havent tested this and you may need to play a little with wether you need a slash in the path or not...

HTH

Rob


Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
I will likely do the marker replacement method.


Thanks for the suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top