lbenezra Posted December 16, 2008 Share Posted December 16, 2008 I use webdeveloper to edit our web site.When I enter the lines below at a aspx.cs file ' it was OK.but when I enter the lines at cs file I get an Error about "server.mappath: - :Error 2 The name 'Server' does not exist in the current context C:\Documents and Settings\liora\My Documents\website\HBWebsite-10-9-08\App_Code\List.cs 64 28 C:\...\HBWebsite-10-9-08\and the same thing about reader.Can anyone explain me why . Liora---------------------- //connect to database string DataPlace = Server.MapPath("App_Data\\hbc_new.mdb"); string connectionString = ConfigurationSettings.AppSettings["DataConnectionString"]; connectionString = connectionString.Replace("TEMP", DataPlace); OleDbConnection m_connection = new OleDbConnection(connectionString); OleDbCommand cmdTemp = m_connection.CreateCommand(); m_connection.Open(); cmdTemp = m_connection.CreateCommand(); cmdTemp.CommandText = "SELECT a.id,a.name_en FROM Activities a WHERE a.parent_id =" + activityID.ToString(); reader = cmdTemp.ExecuteReader(CommandBehavior.Default);---------------------- Link to comment Share on other sites More sharing options...
aspnetguy Posted December 16, 2008 Share Posted December 16, 2008 a .aspx.cs file contains a class that inherits from the Page class. Server, Response, Request, Session, etc are all part of the Page class so any classes that do not inherit from Page cannot use those methods (not normally anyway).Make sure you have the proper using statements in your file.Post the code of the whole file and I'll point out any problems I see. Link to comment Share on other sites More sharing options...
jesh Posted December 16, 2008 Share Posted December 16, 2008 \HBWebsite-10-9-08\App_Code\List.csWith what aspnetguy said, aspx pages inherit from the System.Web.UI.Page which has references to various other classes in it - Server, Request, Response, etc.. I'm guessing your List class does not inherit from the System.Web.UI.Page class (not that it should, mind you).So, what would work in a web page:string DataPlace = Server.MapPath("App_Data\\hbc_new.mdb"); Won't work in List.cs. You'll have to get it from the current HttpContext like so: string DataPlace = System.Web.HttpContext.Current.Server.MapPath("App_Data\\hbc_new.mdb"); Link to comment Share on other sites More sharing options...
lbenezra Posted December 21, 2008 Author Share Posted December 21, 2008 HiThanks for your reply. I just solved it by senting the dataplace string through a function called from aspx.cs file. Link to comment Share on other sites More sharing options...
lbenezra Posted December 21, 2008 Author Share Posted December 21, 2008 HiThanks for your reply. I just solved it by senting the dataplace string through a function called from aspx.cs file. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.