file relative path problem

Ask general questions here.
Ruser
Posts: 24
Joined: Wed Oct 07, 2009 3:26 pm

file relative path problem

Post by Ruser » Wed Oct 21, 2009 10:13 pm

Hi, there,

I call a file in my script like:

CSVConnector.Instance.Open(@"..\..\TestData.csv");
string URL = CSVConnector.Instance.Rows[4]["Value1"].ToString();

I got an error said no row 4 exists, basically cannot read the TestData.csv file.

If I change the script to give full TestData.csv path, it is working properly, so this one works:

CSVConnector.Instance.Open(@"C:\Users\user1\Documents\RanorexStudio Projects\AutomationLib\TestData.csv);
string URL = CSVConnector.Instance.Rows[4]["Value1"].ToString();


The TestData.csv file is at the same folder with Csvconnector.cs inside a project solution.

Anyone has idea here?

Thanks,

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: file relative path problem

Post by Support Team » Thu Oct 22, 2009 9:10 am

Hi Ruser,
check the Environment.CurrentDirectory property before calling CSVConnector.Instance.Open(@"..\..\TestData.csv");. Probably your current dir + relative path is wrong. Attend that the current (working) directory depends on the location of your exe/dll. So if you add a reference to e.g. AutomationLib which call the csvConnector, the current dir is relating to the location of your DLL.

see: http://msdn.microsoft.com/en-us/library ... ctory.aspx

Best regards,
Christian
Ranoex Support Team
.
Image

atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

Re: file relative path problem

Post by atom » Thu Nov 19, 2009 8:16 pm

Or use:

Code: Select all

FileName = path.combine(path.GetDirectory(assembly.getexecutingassembly.location),"myfile.csv")
or something similar