471,089 Members | 1,116 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

GetCurrentDirectory?

Dan
I have built a C# Windows application using a C# library hosted in a DLL.
Both the library and the application need to access some files which at
program installation are placed in the EXE's path; thus, I use
Directory.GetCurrentDirectory() to initialize the default filenames so that
they point to the EXE's path. This happens in the constructor of some
objects (for the DLL) and in the OnLoad event of the EXE's form.

All this works fine in the development workstation (with Visual Studio .NET
and WinXP Pro), and the EXE's path (e.g. ...\MyExe\Bin\Debug or the like) is
retrieved correctly either by the objects in the DLL or in the EXE's OnLoad;
but when I launch the program on a test machine with just Windows ME and
dotnet framework runtime only, the path returned by GetCurrentDirectory is
just the root (C:\)! (I added a test
MessageBox.Show(Directory.GetCurrentDirectory()) instruction to the release
build). Is this anything I'm doing wrong, or any problem with this OS, or
what else?

Thanks to all!
Nov 15 '05 #1
7 6990
> Thanks to all!

use Application.ExecutablePath instead...
Nov 15 '05 #2
Dan
Thanks, this works for the EXE... but I'd prefer to avoid referencing the
Windows.Forms namespace for the classes hosted in an external library (a
DLL), which do not belong to any particular application and are pure
"engine" components without any specific user interface... any idea?

"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message
news:ek*************@TK2MSFTNGP09.phx.gbl...
Thanks to all!


use Application.ExecutablePath instead...

Nov 15 '05 #3
Hi Dan,

I can not reproduce the problem.

I think the Directory.GetCurrentDirectory will
get the current working directory of the application.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemiodirectoryclassgetcurrentdirectorytopi c.asp

while the Application.ExecutablePath will
get the path for the executable file that started the application,
including the executable name.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformsapplicationclassexecutablep athtopic.asp
e.g.
the current directory is c:\
the application is located in the e:\test\test.exe
c:\>e:\test\test.exe
in this case the Directory.GetCurrentDirectory will get c:\
while the Application.ExecutablePath
will get e:\test\test.exe
Did I answer your question?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Dan" <fu***@iol.it>
References: <#t**************@TK2MSFTNGP11.phx.gbl> <ek*************@TK2MSFTNGP09.phx.gbl>Subject: Re: GetCurrentDirectory?
Date: Mon, 8 Sep 2003 17:24:22 +0200
Lines: 14
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <e7**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ppp-217-133-157-157.cust-adsl.tiscali.it 217.133.157.157
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183214
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Thanks, this works for the EXE... but I'd prefer to avoid referencing the
Windows.Forms namespace for the classes hosted in an external library (a
DLL), which do not belong to any particular application and are pure
"engine" components without any specific user interface... any idea?

"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message
news:ek*************@TK2MSFTNGP09.phx.gbl...
> Thanks to all!


use Application.ExecutablePath instead...



Nov 15 '05 #4
Dan
Many thanks, the behaviour of the function now is clear... I can suppose
that the different behaviour in the cited machines happens because VS is
setting the working directory of the debugged application to its output
path, so that this works when debugging or launching it from the IDE but not
when launched from another machine (?). So I'll use something like
Path.GetDirectoryName(Application.ExecutablePath) to get the directory of
the EXE, but this does not apply to a class-library hosted in a DLL: how
could I get the DLL full path in such case?

"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:MP**************@cpmsftngxa06.phx.gbl...
Hi Dan,

I can not reproduce the problem.

I think the Directory.GetCurrentDirectory will
get the current working directory of the application.
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemiodirectoryclassgetcurrentdirectorytopi c.asp

while the Application.ExecutablePath will
get the path for the executable file that started the application,
including the executable name.
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemwindowsformsapplicationclassexecutablep athtopic.asp
e.g.
the current directory is c:\
the application is located in the e:\test\test.exe
c:\>e:\test\test.exe
in this case the Directory.GetCurrentDirectory will get c:\
while the Application.ExecutablePath
will get e:\test\test.exe
Did I answer your question?


Regards,
Peter Huang
Microsoft Online Partner Support

Nov 15 '05 #5
Hi Dan,

In the ClassLibrary, you may try the
Assembly.GetExecutingAssembly().Location which will return the path of the
classlibrary.
Did this answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Dan" <fu***@iol.it>
References: <#t**************@TK2MSFTNGP11.phx.gbl> <ek*************@TK2MSFTNGP09.phx.gbl>
<e7**************@tk2msftngp13.phx.gbl>
<MP**************@cpmsftngxa06.phx.gbl>Subject: Re: GetCurrentDirectory?
Date: Tue, 9 Sep 2003 09:21:58 +0200
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <OP**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ppp-217-133-155-20.cust-adsl.tiscali.it 217.133.155.20
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183365
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Many thanks, the behaviour of the function now is clear... I can suppose
that the different behaviour in the cited machines happens because VS is
setting the working directory of the debugged application to its output
path, so that this works when debugging or launching it from the IDE but notwhen launched from another machine (?). So I'll use something like
Path.GetDirectoryName(Application.ExecutablePat h) to get the directory of
the EXE, but this does not apply to a class-library hosted in a DLL: how
could I get the DLL full path in such case?

"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:MP**************@cpmsftngxa06.phx.gbl...
Hi Dan,

I can not reproduce the problem.

I think the Directory.GetCurrentDirectory will
get the current working directory of the application.

http://msdn.microsoft.com/library/de...-us/cpref/html

/
frlrfsystemiodirectoryclassgetcurrentdirectorytopi c.asp

while the Application.ExecutablePath will
get the path for the executable file that started the application,
including the executable name.

http://msdn.microsoft.com/library/de...-us/cpref/html

/
frlrfsystemwindowsformsapplicationclassexecutablep athtopic.asp
e.g.
the current directory is c:\
the application is located in the e:\test\test.exe
c:\>e:\test\test.exe
in this case the Directory.GetCurrentDirectory will get c:\
while the Application.ExecutablePath
will get e:\test\test.exe
Did I answer your question?


Regards,
Peter Huang
Microsoft Online Partner Support



Nov 15 '05 #6
Dan
Thanks, that's what I was looking for... :-)

"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:7i***************@cpmsftngxa06.phx.gbl...
Hi Dan,

In the ClassLibrary, you may try the
Assembly.GetExecutingAssembly().Location which will return the path of the
classlibrary.
Did this answer your question?

Nov 15 '05 #7
Hi Dan,

I am glad that I can help you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Dan" <fu***@iol.it>
References: <#t**************@TK2MSFTNGP11.phx.gbl> <ek*************@TK2MSFTNGP09.phx.gbl>
<e7**************@tk2msftngp13.phx.gbl>
<MP**************@cpmsftngxa06.phx.gbl>
<OP**************@TK2MSFTNGP09.phx.gbl>
<7i*************@cpmsftngxa06.phx.gbl>Subject: Re: GetCurrentDirectory?
Date: Tue, 9 Sep 2003 15:33:51 +0200
Lines: 12
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <ez**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ppp-217-133-156-178.cust-adsl.tiscali.it 217.133.156.178
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183455
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Thanks, that's what I was looking for... :-)

"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:7i***************@cpmsftngxa06.phx.gbl...
Hi Dan,

In the ClassLibrary, you may try the
Assembly.GetExecutingAssembly().Location which will return the path of the classlibrary.
Did this answer your question?



Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by poppy | last post: by
3 posts views Thread by Maileen | last post: by
4 posts views Thread by roto23 | last post: by
1 post views Thread by pb | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.