Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to get current directory path

Scenario : I've created a library project which provides interface to installer(exe created using install shield).I want to check whether a particular file exists in the installer folder.

I've tried following :

1).  Assembly.GetEntryAssembly().Location

// Throws "Object reference not set to an instance of an object"

2). new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath

// return : C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll

3). Assembly.GetExecutingAssembly().Location

// returns empty string

4). AppDomain.CurrentDomain.BaseDirectory

// returns "C:\Windows\syswow64\" irrespective of the actual path

Could anyone tell me how can I get directory path from where the installer is being executed?

like image 596
JustAProgrammer Avatar asked Sep 14 '18 05:09

JustAProgrammer


1 Answers

You can use

Directory.GetCurrentDirectory();

to get current directory path

import System.IO

like image 66
Mostafiz Avatar answered Sep 25 '22 17:09

Mostafiz