473,387 Members | 1,512 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,387 software developers and data experts.

System IO used with ASP.NET

Hello,

i'm a newbie at asp.net, and i'm developping a site at the moment, and want
to add a sort off logging system.

I would like to create a file on the server side when a error occured.
Now how can i do that?

On my pc i have c:\inetput\wwwroot\sitename

i want the file to become in this directory, but i can't use this path
because when i upload it to a host server, the path will be different. So
how can i make sure the file comes in the directory where my site is
located without statically typing in the path in a string orso?

Or thus someone has a better idea of solving this problem?

thank you
Nov 19 '05 #1
4 1080
On Sun, 17 Apr 2005 10:20:00 -0500, Plop Plop via DotNetMonster.com
<fo***@nospam.DotNetMonster.com> wrote:
Hello,

i'm a newbie at asp.net, and i'm developping a site at the moment, and
want
to add a sort off logging system.

I would like to create a file on the server side when a error occured.
Now how can i do that?

On my pc i have c:\inetput\wwwroot\sitename

i want the file to become in this directory, but i can't use this path
because when i upload it to a host server, the path will be different.
So
how can i make sure the file comes in the directory where my site is
located without statically typing in the path in a string orso?

Or thus someone has a better idea of solving this problem?

thank you


Check out HttpServerUtility.MapPath method, takes a virtual path on the
server and maps to an actual server path:

http://msdn.microsoft.com/library/de...ppathtopic.asp

Note a reference to HttpServerUtility is available thru the Server
property of your Page; i.e. to use this inside one of your pages:

//to create file in same dir as page
Server.MapPath("myFile.txt")

//to create file in parent directory
Server.MapPath("../myFile.txt")

etc

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2

Check out HttpServerUtility.MapPath method, takes a virtual path on the
server and maps to
an actual server path:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwebhttpserverutilityclassmappathtopic.a sp

Note a reference to HttpServerUtility is available thru the Server
property of your Page;
i.e. to use this inside one of your pages:

//to create file in same dir as page
Server.MapPath("myFile.txt")

//to create file in parent directory
Server.MapPath("../myFile.txt")

etc

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #3
One additional note is the concurrency may be hard to maintain when writing
to a file, unless each session has their own log file. Suppose two sessions
(users) encounter an error, and they both try to write to the file at the
same time. Two things can happen, 1) The first one to open the file will
also lock it, but then the second access attempt will error because the file
is locked, or 2) Both will try to write to the file at the same time and
the log entries will become mangled.

There are ways to mitigate this, but just wanted to point out the issues so
that you can design something appropriate. Another alternative might be to
log to the event log.
"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op***************@cowboy.hsd1.mn.comcast.net. ..
On Sun, 17 Apr 2005 10:20:00 -0500, Plop Plop via DotNetMonster.com
<fo***@nospam.DotNetMonster.com> wrote:
Hello,

i'm a newbie at asp.net, and i'm developping a site at the moment, and
want
to add a sort off logging system.

I would like to create a file on the server side when a error occured.
Now how can i do that?

On my pc i have c:\inetput\wwwroot\sitename

i want the file to become in this directory, but i can't use this path
because when i upload it to a host server, the path will be different.
So
how can i make sure the file comes in the directory where my site is
located without statically typing in the path in a string orso?

Or thus someone has a better idea of solving this problem?

thank you


Check out HttpServerUtility.MapPath method, takes a virtual path on the
server and maps to an actual server path:

http://msdn.microsoft.com/library/de...ppathtopic.asp

Note a reference to HttpServerUtility is available thru the Server
property of your Page; i.e. to use this inside one of your pages:

//to create file in same dir as page
Server.MapPath("myFile.txt")

//to create file in parent directory
Server.MapPath("../myFile.txt")

etc

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #4
hehe yep you are right about this.

But i would create a file when a major error occurs, so i never try to open
and append to an already existing file.

Would make a name from a timestamp, added with a session nr orso , i think
that would work?

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.