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

StreamWriter / Problems?

I wrote an custom error handler that works, but why the ErrorLog.txt file is
being created/written in the root web instead of the folder within my web
application?
Root web = C:\Inetpub\wwwroot -&- Web Application Folder =
C:\Inetpub\wwwroot\MySite
See code:
Public Shared Sub LogError(ByVal message As String)
' Get the current HTTPContext
Dim context As HttpContext = HttpContext.Current
' Get location of ErrorLogFile from Web.config file
Dim filePath As String = context.Server.MapPath( "../../ErrorLog.txt")
' Write message to error file

Try
Dim sw As New System.IO.StreamWriter(filePath, True)
sw.WriteLine(message)
sw.WriteLine()
sw.Close()

Catch
' If error writing to file, simply continue
End Try

End Sub
End Class
End Namespace
and if I try to hard code write the error to my ErrorLog text file it in my
web application (such as "MySite/ErrorLog.txt") nothing gets written?
Nov 16 '05 #1
3 1454
Leon <vn*****@msn.com> wrote:
I wrote an custom error handler that works, but why the ErrorLog.txt file is
being created/written in the root web instead of the folder within my web
application?


Well, you're asking for two directories above the web site - what
happens if you use context.Server.MapPath ("ErrorLog.txt") instead?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Nothing the ErrorLog does not get written anywhere?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Leon <vn*****@msn.com> wrote:
I wrote an custom error handler that works, but why the ErrorLog.txt file
is
being created/written in the root web instead of the folder within my web
application?


Well, you're asking for two directories above the web site - what
happens if you use context.Server.MapPath ("ErrorLog.txt") instead?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Leon <vn*****@msn.com> wrote:
Nothing the ErrorLog does not get written anywhere?


Have you tried looking at what context.Server.MapPath returns in the
debugger?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

33
by: | last post by:
Hi, When constructing StreamWriter with the following.. FileStream f = new FileStream(..); StreamWriter s = new StreamWriter(f); Then attempt to write out åäö letters they become garbage. ...
1
by: Vladimir Bezugliy | last post by:
I have a server that listen a socket. And I have next client: TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000); NetworkStream networkStream = socketForServer.GetStream();...
1
by: Daniel | last post by:
i would like to konw when the data sent so that i can close the streamwriter and networkstream is there some sort of call backs/events i have to implement for this to work? if so how? can i just...
5
by: Brendan Miller | last post by:
Hi, I have been having a problem writing the contents of a dataset to a .csv file. When I write to a .csv file and open it with either Excel or Wordpad the "french" characters are wrong. When I...
2
by: RicercatoreSbadato | last post by:
RicercatoreSbadatoI have some big problems with the StreamWriter and MediaDet. I have read that StreamWriter isn't threadsafe from the MSDN.. I have used a lock() but nothing...
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
4
by: Mads Westen | last post by:
Hi, I'm parsing some XML files, and converting them to CSV. I got x number of XML files in a directory, these files do I need to be converted and written to the same CSV file. My problem is...
3
by: Deviant | last post by:
Hello, I have a script that already outputs a file in the correct format how I desire but I have run into a problem after I tried advancing the code. I am building a web application, via php,...
4
by: ºa¤Ö | last post by:
Dear All, Which performance is better? I think 2 is better because only 1 I/O is performed. Am I right? 1. using (StreamWriter sw = File.Append(FileName)) { sw.WriteLine(text1);...
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...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.