Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.CurrentDirectory in C#.NET

Tags:

c#-3.0

The property Environment.CurrentDirectory always returns the path of system directory instead my application directory. In my colleague's PC, it returns application directory.

What is the problem? How can I solve it?

The following code is working for me

ePCRSettings = XMLParser.XmlParser.Deserialize<PCRGeneratorSettings>(string.Format("{0}\\ePCRPDFSettings.xml", AppDomain.CurrentDomain.BaseDirectory));

AppDomain.CurrentDomain.BaseDirectory - Returns the directory E:\MyApplications\.

The following code is not working for me

ePCRSettings = XMLParser.XmlParser.Deserialize<PCRGeneratorSettings>(string.Format("{0}\\ePCRPDFSettings.xml", Environment.CurrentDirectory));

Environment.CurrentDirectory - Returns c:\windows\system32.

This .dll file can be used in VB 6 and ASP.NET applications

like image 279
gopal Avatar asked Aug 24 '09 10:08

gopal


People also ask

How do I change my Currentdirectory environment?

open System open System.IO if Environment. OSVersion. Platform = PlatformID. Win32NT then // Change the directory to %WINDIR% Environment.

What is current directory in C?

For example, if the prompt was "C:\Windows\System32>" the "System32" directory is the current directory, "Windows" is the parent directory, and "C:\" is the drive (root directory). To list the files in the current directory use the dir command, and if you want to change the current directory, use the cd command.


1 Answers

set current directory

Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); //or set executing Assembly location path in param

Environment.CurrentDirectory //now returns your app path
like image 116
Usman Avatar answered Oct 14 '22 02:10

Usman