1

I have 5 Project in One solution In that Email service is one of the Class library i have when i try to get the Directory path its return main project path only here my code.

var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory()+ ".EmailService")
                .AddJsonFile("appsetting.json");
            IConfigurationRoot configuration = builder.Build();

extra i have added a ".EmailService". there is any solution to get path?

  • here some ways to get the path: https://yetanotherchris.dev/csharp/6-ways-to-get-the-current-directory-in-csharp/ – jazb Aug 08 '19 at 05:13
  • why did you add `".EmialService"`?? – jazb Aug 08 '19 at 05:14
  • Possible duplicate of [Get File Path of A File In Your Current Project](https://stackoverflow.com/questions/10704444/get-file-path-of-a-file-in-your-current-project) – Neeraj Kumar Aug 08 '19 at 05:47
  • John b actually what the builder return main project(web) path i have the appseting.json in Email service project so that i statically added ".EmailService" – sivaprakash Aug 08 '19 at 09:01

1 Answers1

0

For .Net Core

Inject IHostingEnvironment env

string path =env.ContentRootPath;

For .Net framework

string _systemPath=System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
KDM
  • 144
  • 8