473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 7146
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Manfred Suttorp | last post by:
If I use the Directory.GetCurrentDirectory() method in the compact framework the app throws a System.NotSupportedException. The documentation on MSDN says it is supported on the compact framework....
1
by: | last post by:
Why ? void foo() { Directory::GetCurrentDirectory() ; } ----------Compile Error----------------------- C2039: 'GetCurrentDirectoryA' : is not a member of 'System::IO::Directory'
2
by: poppy | last post by:
Whenever I use "Directory.getcurrentdirectory" I always get "C:\WINDOWS\system32" despite the fact that the code is running from a subdirectory of wwwroot. Can someone help ? How can I get...
3
by: Maileen | last post by:
Hi, I have a little trouble with the function "Directory.GetCurrentDirectory()". It seems that it keeps into memory the path of the Debug version of my application. It doesn't work correctly...
1
by: moondaddy | last post by:
I have a sample vb .net 2.0 winforms app and am using Oneclick deployment to a remote server. All of the files (DLLs, EXEs, manifests, configs, etc.) seem to get deployed to the target folder on...
1
by: Hasan O. | last post by:
Hi , I have a simple program thats open some file a.txt. When program starts it gets GetCurrentDirectory and finds / opens the a.txt file. But if i create a shortcut on desktop it couldnot...
4
by: roto23 | last post by:
I wrote a complied c# class (SpulClass). In that class I use this to get the directory it resides in.. System.IO.Directory.GetCurrentDirectory(); When I call this this class (dll) from a c#...
1
by: pb | last post by:
I am using asp.net and have some code in a file in the App_Code directory. I also have a text file in the same directory that I want to access. This file will always br in the same directory but I...
0
by: JohnIdol | last post by:
Hi Guys, anyone could help me understand the difference between these two methods? path =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.