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);

      

0


source to share


5 answers


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

.

+3


source


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

+2


source


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

+2


source


+1


source


This seems to compile:

File myFileSystem = new File();
myFileSystem.AppendAllText(logFile, hash, false);

      

0


source







All Articles