Home All Groups Group Topic Archive Search About
Author
28 Jan 2007 12:11 PM
Patrick F
How do you get the path to the folder the program is in.

Lets say i have something like this:

c:\programs\myprogram\another folder\program.exe

now in my program i want to get the path,
c:\programs\myprogram\another folder\

I tried something like:
System.IO.Path.GetFullPath("\\")

but that just returns c:\
Author
28 Jan 2007 1:06 PM
Jeff Gaines
On 28/01/2007 in message
<EFC44928-5EBD-4795-9A2F-86885748F***@microsoft.com> Patrick F wrote:

>How do you get the path to the folder the program is in.
>
>Lets say i have something like this:
>
>c:\programs\myprogram\another folder\program.exe
>
>now in my program i want to get the path,
>c:\programs\myprogram\another folder\
>
>I tried something like:
>System.IO.Path.GetFullPath("\\")
>
>but that just returns c:\

FileInfo fInfo = new FileInfo(c:\programs\myprogram\another
folder\program.exe);
string strFolder = fInfo.DirectoryName;

--
Jeff Gaines
Are all your drivers up to date? click for free checkup

Author
28 Jan 2007 1:21 PM
Patrick F
its not what i am after, i dont know the path. the user takes the program and
put it into a "for me unknown" path on his computer and i need to get the
correct path c:\..... or f:\...
etc

Show quoteHide quote
"Jeff Gaines" wrote:

> On 28/01/2007 in message
> <EFC44928-5EBD-4795-9A2F-86885748F***@microsoft.com> Patrick F wrote:
>
> >How do you get the path to the folder the program is in.
> >
> >Lets say i have something like this:
> >
> >c:\programs\myprogram\another folder\program.exe
> >
> >now in my program i want to get the path,
> >c:\programs\myprogram\another folder\
> >
> >I tried something like:
> >System.IO.Path.GetFullPath("\\")
> >
> >but that just returns c:\
>
> FileInfo fInfo = new FileInfo(c:\programs\myprogram\another
> folder\program.exe);
> string strFolder = fInfo.DirectoryName;
>
> --
> Jeff Gaines
>
Author
28 Jan 2007 1:09 PM
Oliver Sturm
Hello Patrick,

>I tried something like:
>System.IO.Path.GetFullPath("\\")
>
>but that just returns c:\

You should be fine using Path.GetDirectoryName() for your purpose.



                Oliver Sturm
Author
28 Jan 2007 1:33 PM
Otis Mukinfus
On Sun, 28 Jan 2007 04:11:01 -0800, Patrick F
<Patri***@discussions.microsoft.com> wrote:

>How do you get the path to the folder the program is in.
>
>Lets say i have something like this:
>
>c:\programs\myprogram\another folder\program.exe
>
>now in my program i want to get the path,
>c:\programs\myprogram\another folder\
>
>I tried something like:
>System.IO.Path.GetFullPath("\\")
>
>but that just returns c:\

If you are trying to get the path of your executable application you should use
:

string path = Application.ExecutablePath;


Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Author
28 Jan 2007 4:08 PM
Oliver Sturm
>If you are trying to get the path of your executable application you
>should use
>:
>
>string path = Application.ExecutablePath;

Ah :-) I wouldn't have interpreted the OP's question this way, but now I
think this is probably the right answer!


                Oliver Sturm

Bookmark and Share