Asp tutorial. net c # read data files created
<% @ Webhandler language = "c #" class = "averagehandler" %>
Using system;
Using system. web;
Public class averagehandler: ihttphandler
{
Public bool isreusable
{Get {return true ;}}
Public void processrequest (httpcontext ctx)
{
Ctx. response. write ("hello ");
}
}
Cs files
Using system. web
Public sealed class textbuilder: ihttphandler
{
Public void processrequest (httpcontext context)
{
Context. response. clearcontent ();
Context. response. contenttype = "text/plain ";
Context. response. write ("hello world ");
Context. response. end ();
}
Public bool isreusable
{
Get {return true ;}
}
}
Method 2
Binarywriter and binaryreader are used to read and write data, rather than strings. The following code example shows how to write data to and read data from a new, empty file stream (test. data. After a data file is created in the current directory, binarywriter and binaryreader are created at the same time. binarywriter is used to test. data writes integers 0 to 10, test. data leaves a file pointer at the end of the file. After setting the file pointer back to the initial position, binaryreader reads the specified content.
[C #]
Using system;
Using system. io;
Class mystream {
Private const string file_name = "test. data ";
Public static void main (string [] args ){
// Create the new, empty data file.
If (file. exists (file_name )){
Console. writeline ("{0} already exists! ", File_name );
Return;
}
Filestream fs = new filestream (file_name, filemode. createnew );
// Create the writer for data.
Binarywriter w = new binarywriter (fs );
// Write data to test. data.
For (int I = 0; I <11; I ++ ){
W. write (int) I );
}
W. close ();
Fs. close ();
// Create the reader for data.
Fs = new filestream (file_name, filemode. open, fileaccess. read );
Binaryreader r = new binaryreader (fs );
// Read data from test. data.
For (int I = 0; I <11; I ++ ){
Console. writeline (r. readint32 ());
W. close ();
}
}
}
If test. data already exists in the current directory, an ioexception is thrown. Always use filemode. create to create a new file without causing ioexception.
Method 4
Using system. web
Public sealed class textbuilder: ihttphandler
{
Public void processrequest (httpcontext context)
{
Context. response. clearcontent ();
Context. response. contenttype = "text/plain ";
Context. response. write ("hello world ");
Context. response. end ();
}
Public bool isreusable
{
Get {return true ;}
}
}