-1

I deserialize a JSON File in the code below I don't want to use the complete path and if I run this project on any system I won't have any problem. what should I do?

 public static List<DtoCustomer> Deserialize()
            {


            List<DtoCustomer> result =
                    JsonConvert.DeserializeObject<List<DtoCustomer>>(
                        File.ReadAllText(@"C:\Users\Customers\Customers\Properties\customer.json"));
                return result;
            }
        }
nazanin77
  • 47
  • 6

1 Answers1

0

You can use the "current directory" of the application instance (see https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.getcurrentdirectory?view=netframework-4.8)

System.IO.GetCurrentDirectory()

However, that will get you the "current working directory" and is not necessarily the same as the directory where the program executable resides. If you want that, have a look at Getting the absolute path of the executable, using C#?

Application.ExecutablePath
devb
  • 269
  • 1
  • 8