0

I am trying to read xml document and the following is what I did in default.aspx

XmlTextReader reader = new XmlTextReader(Server.MapPath("Config.xml"));

I need to add in "using System.Xml;" Then it is done.

I wanna change that to class. and I did the same thing, but the following error pops up.

Error 2 The name 'Server' does not exist in the current context

And When I right click and resolve, the system give me microsoft.sqlserver which is entirely irrelevant.

Why is that?

2 Answers 2

2

It can't find which 'Server' you are referring to.

Try adding HttpContext.Current before Server.MapPath

HttpContext.Current.Server.MapPath();

It needs

using System.Web;

And make sure you have a reference to System.Web in your project, or if you don't want one, modify the code to take a string for a path as the parameter, and resolve the path prior to calling the method from somewhere which does have access to HttpContext.

Sign up to request clarification or add additional context in comments.

Comments

0

It's part of System.Web

Edit: Beaten by lag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.