Skip to main content

System.IO Namesapce in C#

 System.IO Namesapce in C#

file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.

The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream. The input stream is used for reading data from file (read operation) and the output stream is used for writing into the file (write operation).

From the above definition of file, the C# provides a namespace that enable us to manipulate file in C# called System.IO.

 System.IO is a namespace and it contains a standard IO (input/output) types such as classes, structures, enumerations, and delegates to perform a read/write operations on different sources like file, memory, network, etc.

 System.IO Classes

The table below shows different type of classes that exists in System.IO namespace to perform different operations like creating files, writing to files, reading from files, etc.

 

Class

Description

BinaryReader

This class is useful to read primitive data types from a binary stream

BinaryWriter

It is useful to write primitive types in binary format

BufferedStream

This class is useful to read and write bytes from other streams

Directory

This class provides methods to manipulate the directories and subdirectories such as Create and Move etc

File

The class provides methods to manipulate files like Create, Copy, delete, move etc

FileStream

It is useful to read/write bytes from/to files

MemoryStream

The class is use to read or write bytes that are store in memory

Path

It is use to perform operations on directory path information

Stream

This class is an abstract class and it will provide a methods to transfer bytes to the source.

StreamReader

This class is useful to read a characters from stream by converting bytes into characters using an encoded value.

StreamWriter

This class is useful to write a characters to stream by converting characters into bytes using an encoded value.

StringReader

This class is useful to read from a string.

StringWriter         

This class is useful to write information to string.

TextReader

This class is useful to read a sequential series of characters.

TextWriter 

This class is abstract and it is useful to write a sequential series of characters.

System.IO Structures

The table below shows the different type of structures which exists in System.IO namespace.

 

Structure

Description

WaitForChangedResult

This structure will contain information on the changes that occurred.

System.IO Enumerations

The table below shows the different type of enumerations which exists in System.IO namespace.

 

Enumeration

Description

DriveType 

This will define constants for drive types.

FileAccess  

It defines constants for reading, write, or read/write access to a file.

FileAttributes

It provides attributes for files and directories.

FileMode   

It specifies how an operating system will open the file.

FileOptions

It provides an advanced options for creating a filestream object.

FileShare   

It contains constants to control the access of filestream objects.

HandleInheritability

It is useful to specify whether the underlying handle is inheritable by child processes.

NotifyFilters        

It specifies the changes to watch for in a file or folder.

SearchOption      

It will specifies whether to search the current directory or the current directory and all subdirectories.

SeekOrigin 

It will specifies the position in a stream to use for seeking.

WatcherChangeTypes

It will specifies the changes that might occur to a file or directory.

System.IO Delegates

The table below shows the different type of delegates which exists in System.IO namespace.

 

Delegate

Description

ErrorEventHandler       

This will represent a method that will handle the error event of a FileSystemWatcher object.

FileSystemEventHandler

It will represent a method that will handle the changed, created, or deleted event of a FileSystemWatcher class.

RenamedEventHandler 

It will represent a method that will handle the renamed event of a FileSystemWatcher class.

 References

1.    TutorialPoints

2.    Tutlane

Comments

Popular posts from this blog

Classes in C# Explained

C# Class Explained A class is nothing but an encapsulation of properties and methods that are used to represent a real-time entity, as explained by Guru99 . For instance, if you want to work with Guest’s data as in our previous DataDriven Web application . The properties of the Guest would be the Id, GuestName, Address, Phone number etc of the Guest. The methods would include the entry and modification of Guest data. All of these operations can be represented as a class in C# as shown below. using System; namespace CsharpnaijaClassTutorial {     public class Guest     {         public int Id { get ; set ; }         public string GuestName { get ; set ; }         public string Address { get ; set ; }         public string WhomToSee { get ; set ; }     ...

ASP.NET MVC Views

Views in ASP.NET MVC Application explained Find a related article By  Steve Smith  and  Luke Latham from Microsoft Corporation here In the Model-View-Controller (MVC) pattern, the  view  handles the application's data presentation and user interaction. A view is an HTML template with embedded  Razor markup . Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET MVC, views are  .cshtml  files that use the  C# programming language  in Razor markup. Usually, view files are grouped into folders named for each of the application's  controllers . The folders are stored in a  Views  folder at the root of the application as shown: The  Home  controller is represented by a  Home  folder inside the  Views  folder.  The  Home  folder contains the views for the  About ,  Contact , and  Index...

ASP.NET MVC Routing

ASP.NET MVC Routing ASP.NET MVC routing is a pattern matching system that is responsible for mapping incoming browser requests to specified MVC controller actions. When the ASP.NET MVC application launches then the application registers one or more patterns with the framework's route table to tell the routing engine what to do with any requests that matches those patterns. When the routing engine receives a request at runtime, it matches that request's URL against the URL patterns registered with it and gives the response according to a pattern match. Routing pattern is as follows A URL is requested from a browser, the URL is parsed (that is, break into controller and action), the parsed URL is compared to registered route pattern in the framework’s route table, if a route is found, its process and send response to the browser with the required response, otherwise, the HTTP 404 error is send to the browser. Route Properties ASP.NET MVC routes are res...