473,587 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetCurrentDirec tory?

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.GetCu rrentDirectory( ) 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\D ebug 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 GetCurrentDirec tory is
just the root (C:\)! (I added a test
MessageBox.Show (Directory.GetC urrentDirectory ()) 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 7169
> Thanks to all!

use Application.Exe cutablePath 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****@microso ft.com.no.spam> wrote in message
news:ek******** *****@TK2MSFTNG P09.phx.gbl...
Thanks to all!


use Application.Exe cutablePath instead...

Nov 15 '05 #3
Hi Dan,

I can not reproduce the problem.

I think the Directory.GetCu rrentDirectory will
get the current working directory of the application.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemiodi rectoryclassget currentdirector ytopic.asp

while the Application.Exe cutablePath 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/
frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp
e.g.
the current directory is c:\
the application is located in the e:\test\test.ex e
c:\>e:\test\tes t.exe
in this case the Directory.GetCu rrentDirectory will get c:\
while the Application.Exe cutablePath
will get e:\test\test.ex e
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: GetCurrentDirec tory?
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.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: ppp-217-133-157-157.cust-adsl.tiscali.it 217.133.157.157
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1832 14
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

Thanks, this works for the EXE... but I'd prefer to avoid referencing the
Windows.Form s 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****@microso ft.com.no.spam> wrote in message
news:ek******* ******@TK2MSFTN GP09.phx.gbl...
> Thanks to all!


use Application.Exe cutablePath 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.GetDirecto ryName(Applicat ion.ExecutableP ath) 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.m icrosoft.com> wrote in message
news:MP******** ******@cpmsftng xa06.phx.gbl...
Hi Dan,

I can not reproduce the problem.

I think the Directory.GetCu rrentDirectory will
get the current working directory of the application.
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemiodi rectoryclassget currentdirector ytopic.asp

while the Application.Exe cutablePath 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/ frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp
e.g.
the current directory is c:\
the application is located in the e:\test\test.ex e
c:\>e:\test\tes t.exe
in this case the Directory.GetCu rrentDirectory will get c:\
while the Application.Exe cutablePath
will get e:\test\test.ex e
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.GetExe cutingAssembly( ).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: GetCurrentDirec tory?
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.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: ppp-217-133-155-20.cust-adsl.tiscali.it 217.133.155.20
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1833 65
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.GetDirect oryName(Applica tion.Executable Path) 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.m icrosoft.com> wrote in message
news:MP******* *******@cpmsftn gxa06.phx.gbl.. .
Hi Dan,

I can not reproduce the problem.

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

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

/
frlrfsystemiodi rectoryclassget currentdirector ytopic.asp

while the Application.Exe cutablePath 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

/
frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp
e.g.
the current directory is c:\
the application is located in the e:\test\test.ex e
c:\>e:\test\tes t.exe
in this case the Directory.GetCu rrentDirectory will get c:\
while the Application.Exe cutablePath
will get e:\test\test.ex e
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.m icrosoft.com> wrote in message
news:7i******** *******@cpmsftn gxa06.phx.gbl.. .
Hi Dan,

In the ClassLibrary, you may try the
Assembly.GetExe cutingAssembly( ).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: GetCurrentDirec tory?
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.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: ppp-217-133-156-178.cust-adsl.tiscali.it 217.133.156.178
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1834 55
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

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

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

In the ClassLibrary, you may try the
Assembly.GetExe cutingAssembly( ).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
2037
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. Now, is the method supported or not? -- Thanks in advance Manfred Suttorp
1
5647
by: | last post by:
Why ? void foo() { Directory::GetCurrentDirectory() ; } ----------Compile Error----------------------- C2039: 'GetCurrentDirectoryA' : is not a member of 'System::IO::Directory'
2
1800
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 the current directory on a code behind page ? I dont want the full "C:\e.t.c. Just the current directory name.
3
1738
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 in Release version. Did anyone already have such problem ?
1
2733
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 the client OK and seem to work OK, Except for some additional files I created for the client application. For example, I have a file called myData.xml and myCustomConfix.xml which the windows app uses. In the old 1.1 days (while working in the...
1
1686
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 find real working directory. How can i do this ? this is not working for shortcuts char buf; GetCurrentDirectory(2000, buf);
4
5022
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# windows application this.... System.IO.Directory.GetCurrentDirectory(); returns the correct path (C:\Roto\Work\MyProject)
1
1372
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 will not know the absolute path. When I try... Dim s As String = Directory.GetCurrentDirectory I get
0
1358
by: JohnIdol | last post by:
Hi Guys, anyone could help me understand the difference between these two methods? path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:/", "")); path_Startup = System.IO.Directory.GetCurrentDirectory(); I am getting the same result.
0
8352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8222
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5723
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2367
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.