It depends on where you want to get the current directory you should do it:
using System.Console;
using System.IO;
using System.Reflection;
public class Program {
public static void Main() {
WriteLine(Path.Combine(Directory.GetCurrentDirectory(), @"EmailTemplate/email.html"));
WriteLine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"EmailTemplate/email.html"));
}
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
The first form with Directory.GetCurrentDirectory()
takes the current directory that the application is accessing. It can be the same directory as the application or not. You have to see if this is what you want.
If you want to make sure you take the location where the app is you have to use the second form that picks up the Assembly.GetExecutingAssembly().Location
.
If the criterion is another to find out which directory should be used as the basis, you have to find out what the criterion is and choose the method that returns the appropriate information. If neither of these solve the problem because the basis is different, give more information on the question for me to put a new option.
Note that the Path.Combine()
is used to turn the two parts of the path into a valid and complete path.
As a curiosity Environment.CurrentDirectory()
produces exactly the same Directory.GetCurrentDirectory()
. In fact one calls the other.
What kind of application? Web, WCF, Webservice, Winforms???
– Arthur Menezes