vendredi 5 février 2016

How do i get a relative path of a file when running my code in debug for coded ui

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"

Aucun commentaire:

Enregistrer un commentaire