开发者

Error in class file from asp.net

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 er开发者_开发百科ror 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?


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.


It's part of System.Web

Edit: Beaten by lag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜