Connecting Tech Pros Worldwide Help | Site Map

Server.MapPath

Member
 
Join Date: Apr 2007
Location: india
Posts: 111
#1: Sep 12 '08
Hi All

I am create general function (App_Code/commonclass.cs )

The page contains below function
Expand|Select|Wrap|Line Numbers
  1.  public void adderrlogstring(string strcurdate, string ipAddress, string sFilename, string butevent, string errmessage)
  2.     {
  3.         System.IO.StreamReader StreamReader1 = new System.IO.StreamReader(Server.MapPath("Errorfilelog.txt"));
  4.         string preverr = StreamReader1.ReadToEnd();
  5.         StreamReader1.Close();
  6.  
  7.         System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(Server.MapPath("Errorfilelog.txt"));
  8.         //errorlog datetime \t machineip \t pagename \t actioname\t errormessage
  9.  
  10.         string curerror = strcurdate + "\t" + ipAddress + "\t" + sFilename + " \t Button2_Click2 \t" + errmessage;
  11.         curerror = curerror + "\r\n" + preverr;
  12.         StreamWriter1.WriteLine(curerror);
  13.         StreamWriter1.Close();
  14.     }
  15.  
  16.  
but this function got some error

error : The name 'Server' does not exist in the current context


Pls help me
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 700
#2: Sep 12 '08

re: Server.MapPath


Server.MapPath("."+"\Error.txt");

try that ....
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#3: Sep 12 '08

re: Server.MapPath


You can't use Server.MapPath in the classes in your App_Code directory.
Member
 
Join Date: Apr 2007
Location: india
Posts: 111
#4: Sep 30 '08

re: Server.MapPath


hi All

pls use like this

System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(HttpContext.Current.Server. MapPath("Errorfilelog.txt"));


ie) Server.MapPath("Errorfilelog.txt") replace with HttpContext.Current.Server.MapPath("Errorfilelog.t xt")

Thanks
Reply