How to write something to a .txt file from an .aspx file (C #)
This code doesn't seem to compile, I just need to write something to a small text log file (newline to end of file).
<%@ Import Namespace="System.IO" %>
void Page_Load( object sender, EventArgs e ){
FileSystem myFileSystem = new FileSystem();
myFileSystem.WriteAllText(logFile, hash, false);
I don't see any class called FileSystem in the namespaceSystem.IO
. Is this something new in .NET 4.0 that you are trying to use?
Note that the class File
has a static method called WriteAllText
. Is this what you mean?
EDIT: Add to the file instead File.AppendAllText
.
FileSystem is a class from the VisualBasic namespace:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.aspx
Have a look at the FileStream class in C #:
http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx
The FileSystem is located at Microsoft.VisualBasic.File.IO. You will have to reference this.
Though you probably don't want FileSystem at all. You probably want System.IO.File
No doubt log4net! http://logging.apache.org/log4net/index.html
This seems to compile:
File myFileSystem = new File();
myFileSystem.AppendAllText(logFile, hash, false);