'How to get relative path in Integration Testing in c#

Problem

I am trying to test my importing service in which I have to provide file which is save in the same solution but different folder and also there are bunch of project in it too and this folder is out of the projects. I want this path to be absolute path how can I do this?

I am doing in this way

string filePath = Path.GetFullPath(@"E:\Development\Project\Misc Artifacts\ImportFileSamples\city.txt");


Solution 1:[1]

Server.MapPath("~") gives you root path relative to your application. You can specify the rest of the path and use it to fetch your file.

Like Server.MapPath("/ImportFileSamples")

You already have the absolute path.

Solution 2:[2]

you can use this to find the relative path.

var relativePath = Path.GetRelativePath(
@"C:\X\API\APITest.Tests\IntegrationTest\ServiceLayerTests"
@"C:\X\API\API.Test.Tests\Images\)";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Teja
Solution 2 Chathu.Thanthrige