By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

Startup path

P: n/a
JJ
Hi,

Using the app.config scenario and I added a Connectionstring to appSettings
area in xml. In the value string I have the datasource equal to a absolute
path on my dev machine. Now how can I set it to be relative to where my
project gets deployed to? Do I use Application.Startup in the connection
string startup as so :

<appSettings>
<add key="myCon" value="{"Jet OLEDB:Database Password=;Data Source=" +
Application.Startup + "EMSWinDB.mdb';Password=;"};
</add>
</appSettings>

Or is there a better way, more effiecent way of doing this?

Thanks,

JJ
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi JJ,

If you want to dinamically change it you will have to do so in code, what
you can do is split the Connectionstring in two parts and later in the code
concatenate it with the dinamic value:
something like this:

connection.ConnectionString =
System.Configuration.ConfigurationSettings.AppSett ings["myCon"] +
Application.Startup .....

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"JJ" <jm***@bellatlantic.net> wrote in message
news:u6*************@TK2MSFTNGP12.phx.gbl...
Hi,

Using the app.config scenario and I added a Connectionstring to appSettings area in xml. In the value string I have the datasource equal to a absolute
path on my dev machine. Now how can I set it to be relative to where my
project gets deployed to? Do I use Application.Startup in the connection
string startup as so :

<appSettings>
<add key="myCon" value="{"Jet OLEDB:Database Password=;Data Source=" + Application.Startup + "EMSWinDB.mdb';Password=;"};
</add>
</appSettings>

Or is there a better way, more effiecent way of doing this?

Thanks,

JJ

Nov 15 '05 #2

P: n/a
string path = Server.MapPath(null);

Server.MapPath Returns the physical file path that corresponds to the
specified virtual path on the Web server. If path is null, MapPath returns
the full physical path to the directory containing the current application.

If you put your data in a "Data" sub directory on your site, then you will
want to use

string datapath = Server.MapPath("Data");

If your site is running on the server's "C:\inetpub\wwwroot\MySite"
directory then after the above call, datapath will contain
"C:\inetpub\wwwroot\MySite\Data".

--
Leit Rachsor
Nov 15 '05 #3

P: n/a
Hi Leit,

Sorry not to mention it but this is a Win form App not asp.net.

Thanks,

JJ

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

P: n/a
Oh! Sorry about that. I don't know what I was thinking.

Add "using System.IO;"

Then ...

string apppath = Path.GetDirectoryName(Application.ExecutablePath);

will do the same thing.

--
Leit Rachsor
Nov 15 '05 #5

P: n/a
Belay my last posting!

Now I feel like a real idiot. But I learned something today!

I have always used Path.GetDirectoryName(Application.ExecutablePath); to get
the application's startup path. I *NEVER KNEW* that
"Application.StartupPath" existed. It was all the way down at the bottom of
the Intellisense list. ;o)

cool.

In that case...

string datapath = Path.Combine(Application.StartupPath, @"Data\");

will do the same thing as my earlier posting.

--
Leit Rachsor
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.