Startup path

  • Thread starter Thread starter JJ
  • Start date Start date
J

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
 
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.AppSettings["myCon"] +
Application.Startup .....

Hope this help,
 
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".
 
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.
 
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.
 
Back
Top