473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Server.MapPath

115 100+
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
Sep 12 '08 #1
3 2489
PRR
750 Expert 512MB
Server.MapPath("."+"\Error.txt");

try that ....
Sep 12 '08 #2
Curtis Rutland
3,256 Expert 2GB
You can't use Server.MapPath in the classes in your App_Code directory.
Sep 12 '08 #3
yogarajan
115 100+
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
Sep 30 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a...
4
by: Laphan | last post by:
Hi All Sorry to be irate, but the whole concept of Server.MapPaths really has me in a tiswas!! In order to confirm once and for all, could you please advise me on the following: 1) There...
6
by: darrel | last post by:
I have some functions that are reading/writing to the file system. As such, they use server.mapPath a lot to navigate it all. Since I'm using these functions numerous times throughout my...
7
by: benoit | last post by:
Hi, if I write this code to retrieve a folder on the server Server.mappath("/DATA") I get this error message System.InvalidOperationException: Failed to map the path '/DATA' the virtual...
14
by: Lorenzo | last post by:
Hello, I have a web application with a virtual directory in it. With 'virtual directory' i mean a folder whose physical path is different from the physical path of the application, but in which...
5
by: MichiMichi | last post by:
When using Server.MapPath on IIS 5 on my localhost everything works well. All of the following commands are executed without any error Response.Write(Server.MapPath("/app_test") & "<br>")...
4
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
by: rn5a | last post by:
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path. Assuming that a file named...
6
by: withers | last post by:
If I run Server.MapPath("/") on my operational Internet server I get, correctly, the physical path to the directory my page is in (d:\.... \...\htdocs). If I run Server.MapPath("/") on my...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have one line code in my program, occasionaly I will receive the following error: "The Path parameter for the MapPath method did not correspond to a known path" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.