JamesBrownIsDead
JamesBrownIsDead

Reputation: 4793

App config asp.net

Let's say I have a class called AppConfig:

public static class AppConfig
{
    private static XDocument config = 

    public static AppConfig()
    {

    }
}

How do I XDocument.Load the ~App.Config file? Isn't it something like Server.SOMETHING? What namespaces do I need to include>

Upvotes: 0

Views: 783

Answers (3)

Ron Savage
Ron Savage

Reputation: 11079

I'm not sure why you're trying to do that ... if you want to access the values in your web.config or app.config (for client apps) there is already a wrapper class set up to do that named My.Settings.

Those app.config and web.config files are a pain in the keester to deal with directly.

Upvotes: 0

marc_s
marc_s

Reputation: 754220

XDocument.Load(HttpContext.Current.Server.MapPath("~/web.config")); 

is probably what you're looking for. This helper class "Server" lives on the "current" HttpContext inside the System.Web namespace, so add a

using System.Web;

to your code.

Marc

Upvotes: 2

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

I think what is his problem, he is not able to get server class in his class

Server is property of the Page class that your page inherits from, it not a global. if you are trying to access from a class, use

HttpContext.Current.Server.MapPath("");

and add reference

using System.Web;

OR can be get directly

System.Web.HttpContext.Current.Server.MapPath("");

Upvotes: 1

Related Questions