0

I am writing a class library and referring it in a WCF Service.

In this class library , i need to get the physical path of the app.config file.

It is working when hard coded with full physical path. But, i do not want to do this way.

Please see my code:

  private static void loadConfig()
        {
            strConfigpath = "app.config";
            log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.GetFullPath(strConfigpath)) );
        }

I tried using Path.GetFullPath(). But, it is giving wrong result.

I cannot use Server.MapPath() since it is not a web service or web application.

How to do this ? Ant thoughts or suggestions ?

Sai Avinash
  • 4,683
  • 17
  • 58
  • 96

1 Answers1

0

Use the FullName property

    string fileName = "app.config";
    FileInfo f = new FileInfo(fileName);
    string fullname = f.FullName;
    f.DirectoryName; //This will give the folder path which is having the file

try something like this,

string folder = System.Web.HttpContext.Current != null ?
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_data") :          System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

refered : Get the file path of current application's config file

Community
  • 1
  • 1
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396