In C #, you can use caller information (available from C # 5 / VS2012). Just declare the method as follows:
string GetCurrentFileName([System.Runtime.CompilerServices.CallerFilePath] string fileName = null)
{
return fileName;
}
And call it without specifying an optional parameter:
string scriptPath = GetCurrentFileName();
source
share