Re: get Application.ExecutablePath from an external class by Ben
Ben
Mon Jul 26 13:23:39 CDT 2004
You should be able to access the Assembly object from your class. It's just
a matter of making sure that you are using the namespace for the Assembly
class. You can do this by either adding the following line to the beginning
of your source file:
using System.Reflection;
or, you can reference the Assembly class directly using:
string sLocation =
System.Reflection.Assembly.GetExecutingAssembly().Location;
Hope this helps.
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"Logan McKinley" <logan@globalweb.net> wrote in message
news:e8rrrYzcEHA.2908@TK2MSFTNGP10.phx.gbl...
> Thanks for the ideas
> Ii should clairify that this is for a windows application written in C#
that
> i am going to distribute to users so i can't be sure where they will
install
> it. I don't seem to have access to Assembly from my class either and i
was
> hoping to stay way from passing something in every time i use the class.
I
> have been told that this is likely possible through reflection but i have
> not been able to figure it out.
> Thanks for the help,
> ~Logan
>
>
>
>
> "Ben Lucas" <ben@nospam.solien.nospam.com> wrote in message
> news:qoqdnXnNn6SUr5jcRVn-tw@comcast.com...
> > I see a several possible ways to find out where your application is
> > executing. First, you could pass the Application object into your data
> > class (perhaps on construction). Personally, I don't necessarily like
> this
> > approach because it mixes the data layer with the UI layer a bit too
much.
> >
> > Another approach would be to get the executing assembly's path
> > (Assembly.GetExecutingAssembly().Location). This will give you the path
> to
> > the executing assembly (presumably in the bin directory) and you can
> > navigate to your Access database from ther.
> >
> > A third approach (and the one that I would probably choose) is to
include
> > the path to your database in a configuration setting. This can be done
by
> > adding the configuration setting to your web.config file. You can then
> > retrieve this value using the ConfigurationSettings class.
> >
> > Ben Lucas
> > Lead Developer
> > Solien Technology, Inc.
> > www.solien.com
> >
> > "Logan McKinley" <logan@globalweb.net> wrote in message
> > news:Op%23vRoycEHA.560@TK2MSFTNGP10.phx.gbl...
> > > I am trying to create a data class that will hold all of my access
> > database
> > > stuff. My problem is that i want to be able to use a DSNless
connection
> > and
> > > i will not always know the absolute path so i want to use
> > > Application.ExecutablePath or something similar but i don't have
access
> to
> > > that from within my data class. Is there any way to do this?
> > > Thanks in advance
> > >
> > >
> >
> >
>
>