0

I'm trying not to hard code my path, but I have not been able to figure our a way to get to an xml file that I have included in my project under a folder labeled Datasource. Here is my latest code that I have tried which still doesn't work.

        public static string myAssemblyDirectory
    {
        get
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }
    }



        string fileName = xmlFileName;

        string path = Path.Combine(myAssemblyDirectory, @"DataSource\" + fileName);

        XmlDocument xDoc = new XmlDocument();

        xDoc.Load(path);

Here is the output for the path that I'm getting which is putting it in my test results output folder.

"C:\MyAutomation\Automated_Test_Projects\AutomationProjects\MiserReleaseTestSuites\TestResults\marcw_ISD2005M 2016-02-05 10_15_17\Out\DataSource\Miser_Login_Dts.xml"

If possible I'd like to point it to "C:\MyAutomation\Automated_Test_Projects\AutomationProjects\MiserReleaseTestSuites\MiserReleaseTestSuites\DataSource\Miser_Login_DTs.xml"

skinnyWill
  • 327
  • 2
  • 18

2 Answers2

1

".." Can be used to go to the relative parent directory. "." Refers to the current directory.

You can combine these to form a relative path that starts higher up in the directory tree.

In your example you need to go 3 directories higher than the out folder and then into the MiserReleaseTestSuites\DataSource folder. Combining this produces

@"..\..\..\MiserReleaseTestSuites\DataSource\"

James
  • 9,774
  • 5
  • 34
  • 58
0

You can deploy the file in the same manner as you would when data driving the tests. See https://stackoverflow.com/a/25742114/546871

The TestContext class contains several fields with "directory" in their names. These can be used to access the various directories associated with running the tests. See also https://stackoverflow.com/a/19682311/546871

Community
  • 1
  • 1
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87