Reputation: 135
public static void ReadingExcelSheetData()
{
Console.WriteLine("GetCurrentDirectory Returns :" + System.IO.Directory.GetCurrentDirectory());
Console.ReadLine();
controller = new XlsReader(System.IO.Directory.GetCurrentDirectory() + "\\TestCode\\Config\\controller.xls");
testData = new XlsReader(System.IO.Directory.GetCurrentDirectory() + "\\TestCode\\Config\\testData.xls");
}
public static void Main()
{
ReadingExcelSheetData();
Console.ReadLine();
}
Here System.IO.Directory.GetCurrentDirectory() returns E:\seleniumwith C#\myprojectsC#\Pluralsite\TestCode\TestCode\bin\Debug.
But we have our controller sheet at E:\seleniumwith C#\myprojectsC#\Pluralsite\TestCode\TestCode\Config location.
I just want the path upto E:\seleniumwith C#\myprojectsC#\Pluralsite\TestCode\TestCode. How to get that. Can someone please help me out.
Thanks,
Nilanjan.
Upvotes: 0
Views: 2579
Reputation: 79
Directory.GetParent(Assembly.GetExecutingAssembly().Location)
will return you fullpath to your {fullpaht}\debug\bin. Remember bin folder may or may not have your file depending if you have set the property "Copy to Output Directory" to either "copy if newer" or "copy alway." If in the event you haven't you can try something like
Directory.GetParent(Assembly.GetExecutingAssembly().Location).Parent.Parent
until it takes you to the desired folder location then you can append @"\config\controller.xls".
using System.IO;
using System.Reflection;
Upvotes: 1
Reputation: 3834
Application.StartupPath
property helps to find application startup path.
For your SO problem following code will work.
string exeFolder = (System.IO.Path.GetDirectoryName(Application.StartupPath)).Substring(0, (System.IO.Path.GetDirectoryName(Application.StartupPath)).Length - 3);
Upvotes: 0
Reputation: 467
controller = new XlsReader(@"E:\seleniumwith C#\myprojectsC#\Pluralsite\TestCode\TestCode\Config\controller.xls");
testData = new XlsReader(@"E:\seleniumwith C#\myprojectsC#\Pluralsite\TestCode\TestCode\Config\testData.xls");
Upvotes: 0