It is my first time with C# (I wrote in Java before). I tried to get the path to the json file "movies-filtered.json" located in directory "Resources" by this way:
string fileName = "movies-filtered.json";
string path = Path.Combine(Environment.CurrentDirectory, "..\\..\\Resources\\", fileName);
Console.WriteLine(path);
Console.WriteLine("Hold the application: ");
string Number2 = Console.ReadLine();
But the output of this Console.WriteLine(path) is: C:\Users\xxxxxx\Movie_Library_C#\MovieLibrary\MovieLibrary\bin\Debug....\Resources\movies-filtered.json
The "xxxxxx" hide some part of the path.
I tried to get out of the "bin/Debug" directories and then from "MovieLibrary" go to "Resources" directory and there is "movies-filtered.json" file which I want to get. But it doesn't work like that.
Could anyone help me to solve this issue? I will be gratefull for help.
EDITED
My goal is to be able to load json file from directory "Resources". I want to do this in Dao.cs class by the method "LoadObjectsFromJsonFile":
public class Dao
{
private const char delimiter = ',';
private IList<Movie> Movies;
public IList<Movie> GetMovies { get => Movies; set => Movies = value; }
public Dao()
{
this.Movies = null;
}
public void LoadObjectsFromJsonFile()
{
string Filepath = "../MovieLibrary/Resources/movies-filtered.json";
using (StreamReader Sr = new StreamReader(Filepath))
{
var Json = Sr.ReadToEnd();
Movies = JsonConvert.DeserializeObject<List<Movie>>(Json);
}
}