Official Study Materials for Computer Science
Access comprehensive study materials and useful resources for .NET Technology using the Application of .NET Technology Unit 07 File and Database Applications Notes Set 01. Designed to align with the 2026-27 academic guidelines, these advanced resources help Computer Science students reinforce core concepts beyond standard textbooks.
Advanced Resources for Computer Science
Access the complete useful resource PDF for Computer Science below. Regular practice with these targeted academic notes builds familiarity with complex topics and helps secure higher marks in final school evaluations.
This page explains file handling in VB.Net with streams and the System.IO classes, including FileStream, StreamReader, StreamWriter, BinaryReader, BinaryWriter, DirectoryInfo and FileInfo with worked programs. It also covers the common dialog boxes and the DialogResult values returned by ShowDialog.
File Access
A 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. File is used to store data, and using that we can operate on the data. The operations are:
1. Reading,
2. Writing,
3. Close, etc.
Stream
The stream is basically the sequence of bytes passing through the communication path. There are two main streams:
1. Input stream: The input stream is used for reading data from file (read operation).
2. Output stream: The output stream is used for writing into the file (write operation).
VB.Net I/O Classes
The System.IO namespace has various classes that are used for performing various operations with files, like creating and deleting files, reading from or writing to a file, closing a file, etc. Some commonly used non-abstract classes in the System.IO namespace are:
| I/O Class | Description |
|---|---|
| BinaryReader | Reads primitive data from a binary stream. |
| BinaryWriter | Writes primitive data in binary format. |
| BufferedStream | A temporary storage for a stream of bytes. |
| Directory | Helps in manipulating a directory structure. |
| DirectoryInfo | Used for performing operations on directory. |
| DriveInfo | Provides information for the drives. |
| File | Helps in manipulating files. |
| FileInfo | Used for performing operations on files. |
| FileStream | Used to read from and write to any location in a file. |
| MemoryStream | Used for random access of streamed data stored in memory. |
| Path | Performs operations on path information. |
| StreamReader | Used for reading characters from a byte stream. |
| StreamWriter | Is used for writing characters to a stream. |
| StringReader | Is used for reading from a string buffer. |
| StringWriter | Is used for writing into a string buffer. |
The FileStream Class
The FileStream class in the System.IO namespace helps in reading from, writing to and closing files. This class derives from the abstract class Stream. You need to create a FileStream object to create a new file or open an existing file. The syntax for creating a FileStream object is as follows:
Dim <object_name> As FileStream = New FileStream
(<file_name>, <FileMode Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>)For example, for creating a FileStream object f1 for reading and writing a file named test.dat:
Dim f1 As FileStream = New FileStream("test.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite)The following program demonstrates use of the FileStream class:
Imports System.IO
Module fileProg
Sub Main()
Dim f1 As FileStream = New FileStream("test.dat", _
FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim i As Integer
For i = 1 To 20
f1.WriteByte(CByte(i))
Next i
f1.Position = 0
For i = 0 To 20
Console.Write("{0} ", f1.ReadByte())
Next i
f1.Close()
Console.ReadKey()
End Sub
End ModuleWhen the code is compiled and executed, it produces the following result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -1
The FileMode enumerator defines various methods for opening files. The members of the FileMode enumerator are:
| Member | Description |
|---|---|
| Append | It opens an existing file and puts cursor at the end of file, or creates the file, if the file does not exist. |
| Create | It creates a new file. |
| CreateNew | It specifies to the operating system that it should create a new file. |
| Open | It opens an existing file. |
| OpenOrCreate | It specifies to the operating system that it should open a file if it exists, otherwise it should create a new file. |
| Truncate | It opens an existing file and truncates its size to zero bytes. |
FileShare
FileShare enumerators have the following members:
| Member | Description |
|---|---|
| Inheritable | It allows a file handle to pass inheritance to the child processes. |
| None | It declines sharing of the current file. |
| Read | It allows opening the file for reading. |
| ReadWrite | It allows opening the file for reading and writing. |
| Write | It allows opening the file for writing. |
Advanced File Operations in VB.Net
The advanced file operations use the following classes:
1. StreamReader and StreamWriter classes.
2. BinaryReader and BinaryWriter classes.
3. The DirectoryInfo Class.
4. The FileInfo Class.
However, to utilize the immense powers of System.IO classes, you need to know the commonly used properties and methods of these classes.
The StreamReader Class
The StreamReader class also inherits from the abstract base class TextReader that represents a reader for reading series of characters. The following are some of the commonly used methods of the StreamReader class:
Public Overrides Sub Close
It closes the StreamReader object and the underlying stream and releases any system resources associated with the reader.
Public Overrides Function Peek As Integer
Returns the next available character but does not consume it.
Public Overrides Function Read As Integer
Reads the next character from the input stream and advances the character position by one character.
The following program demonstrates use of the StreamReader:
Imports System.IO
Module fileProg
Sub Main()
Try
' Create an instance of StreamReader to read from a file.
' The using statement also closes the StreamReader.
Using sr As StreamReader = New StreamReader("e:/jamaica.txt")
Dim line As String
' Read and display lines from the file until the end of
' the file is reached.
line = sr.ReadLine()
While (line <> Nothing)
Console.WriteLine(line)
line = sr.ReadLine()
End While
End Using
Catch e As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(e.Message)
End Try
Console.ReadKey()
End Sub
End ModuleThe StreamWriter Class
The StreamWriter class inherits from the abstract class TextWriter that represents a writer, which can write a series of character. Some of the most commonly used methods of StreamWriter class:
Public Overrides Sub Close
Closes the current StreamWriter object and the underlying stream.
Public Overrides Sub Flush
Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream.
Public Overridable Sub Write ( value As Boolean )
Writes the text representation of a Boolean value to the text string or stream. (Inherited from TextWriter.)
Public Overrides Sub Write ( value As Char )
Writes a character to the stream.
Public Overridable Sub Write ( value As Decimal )
Writes the text representation of a decimal value to the text string or stream.
The following program demonstrates use of the StreamWriter Class:
Imports System.IO
Module fileProg
Sub Main()
Dim names As String() = New String() {"Zara Ali", _
"Nuha Ali", "Amir Sohel", "M Amlan"}
Dim s As String
Using sw As StreamWriter = New StreamWriter("names.txt")
For Each s In names
sw.WriteLine(s)
Next s
End Using
' Read and show each line from the file.
Dim line As String
Using sr As StreamReader = New StreamReader("names.txt")
line = sr.ReadLine()
While (line <> Nothing)
Console.WriteLine(line)
line = sr.ReadLine()
End While
End Using
Console.ReadKey()
End Sub
End ModuleThe BinaryReader Class
The BinaryReader class is used to read binary data from a file. A BinaryReader object is created by passing a FileStream object to its constructor. Some of the commonly used methods of the BinaryReader class:
Public Overridable Sub Close
It closes the BinaryReader object and the underlying stream.
Public Overridable Function Read As Integer
Reads the characters from the underlying stream and advances the current position of the stream.
Public Overridable Function ReadBoolean As Boolean
Reads a Boolean value from the current stream and advances the current position of the stream by one byte.
The BinaryWriter Class
The BinaryWriter class is used to write binary data to a stream. A BinaryWriter object is created by passing a FileStream object to its constructor. Some of the commonly used methods of the BinaryWriter class:
Public Overridable Sub Close
It closes the BinaryWriter object and the underlying stream.
Public Overridable Sub Flush
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
Public Overridable Function Seek ( offset As Integer, origin As SeekOrigin ) As Long
Sets the position within the current stream.
Public Overridable Sub Write ( value As Boolean )
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing true.
Example
Example for BinaryReader and BinaryWriter classes:
Imports System.IO
Module fileProg
Sub Main()
Dim bw As BinaryWriter
Dim br As BinaryReader
Dim i As Integer = 25
Dim d As Double = 3.14157
Dim b As Boolean = True
Dim s As String = "I am happy"
'create the file
Try
bw = New BinaryWriter(New FileStream("mydata", FileMode.Create))
Catch e As IOException
Console.WriteLine(e.Message + vbCrLf + " Cannot create file.")
Return
End Try
'writing into the file
Try
bw.Write(i)
bw.Write(d)
bw.Write(b)
bw.Write(s)
Catch e As IOException
Console.WriteLine(e.Message + vbCrLf + " Cannot write to file.")
Return
End Try
bw.Close()
'reading from the file
Try
br = New BinaryReader(New FileStream("mydata", FileMode.Open))
Catch e As IOException
Console.WriteLine(e.Message + vbCrLf + " Cannot open file.")
Return
End Try
Try
i = br.ReadInt32()
Console.WriteLine("Integer data: {0}", i)
d = br.ReadDouble()
Console.WriteLine("Double data: {0}", d)
b = br.ReadBoolean()
Console.WriteLine("Boolean data: {0}", b)
s = br.ReadString()
Console.WriteLine("String data: {0}", s)
Catch e As IOException
Console.WriteLine(e.Message + vbCrLf + " Cannot read from file.")
Return
End Try
br.Close()
Console.ReadKey()
End Sub
End ModuleWhen the above code is compiled and executed, it produces the following result:
Integer data: 25 Double data: 3.14157 Boolean data: True String data: I am happy
The DirectoryInfo Class
The DirectoryInfo class is derived from the FileSystemInfo class. It has various methods for creating, moving, and browsing through directories and subdirectories. This class cannot be inherited. Following are some commonly used properties of the DirectoryInfo class:
| Property | Description |
|---|---|
| Attributes | Gets the attributes for the current file or directory. |
| CreationTime | Gets the creation time of the current file or directory. |
| Exists | Gets a Boolean value indicating whether the directory exists. |
| Extension | Gets the string representing the file extension. |
| FullName | Gets the full path of the directory or file. |
| LastAccessTime | Gets the time the current file or directory was last accessed. |
| Name | Gets the name of this DirectoryInfo instance. |
The FileInfo Class
The FileInfo class is derived from the FileSystemInfo class. It has properties and instance methods for creating, copying, deleting, moving, and opening of files, and helps in the creation of FileStream objects. This class cannot be inherited. Following are some commonly used properties of the FileInfo class:
| S.N | Property | Description |
|---|---|---|
| 1 | Attributes | Gets the attributes for the current file. |
| 2 | CreationTime | Gets the creation time of the current file. |
| 3 | Directory | Gets an instance of the directory which the file belongs to. |
| 4 | Exists | Gets a Boolean value indicating whether the file exists. |
| 5 | Extension | Gets the string representing the file extension. |
| 6 | FullName | Gets the full path of the file. |
| 7 | LastAccessTime | Gets the time the current file was last accessed. |
| 8 | LastWriteTime | Gets the time of the last written activity of the file. |
| 9 | Length | Gets the size, in bytes, of the current file. |
| 10 | Name | Gets the name of the file. |
Example
Example for DirectoryInfo class and the FileInfo class:
Imports System.IO
Module fileProg
Sub Main()
'creating a DirectoryInfo object
Dim mydir As DirectoryInfo = New DirectoryInfo("c:\Windows")
'getting the files in the directory, their names and size
Dim f As FileInfo() = mydir.GetFiles()
Dim file As FileInfo
For Each file In f
Console.WriteLine("File Name: {0} Size: {1} ", file.Name, file.Length)
Next file
Console.ReadKey()
End Sub
End ModuleWhen you compile and run the program, it displays the names of files and their size in the Windows directory.
Dialog Box
There are many built-in dialog boxes to be used in Windows forms for various tasks like opening and saving files, printing a page, providing choices for colors, fonts, page setup, etc., to the user of an application. These built-in dialog boxes reduce the developer's time and workload. All of these dialog box control classes inherit from the CommonDialog class and override the RunDialog() function of the base class to create the specific dialog box. It all works like a normal windows application.
Common Dialog Boxes
Common dialog boxes are predefined standard dialog boxes for:
1. File Opening and Saving,
2. Font and Color selection,
3. Printing and Previewing.
They appear in the Component Tray. The RunDialog() function is automatically invoked when a user of a dialog box calls its ShowDialog() function. The ShowDialog method is used to display all the dialog box controls at run-time. It returns a value of the type of DialogResult enumeration. The values of DialogResult enumeration are:
1. Abort - returns DialogResult.Abort value, when user clicks an Abort button.
2. Cancel - returns DialogResult.Cancel, when user clicks a Cancel button.
3. Ignore - returns DialogResult.Ignore, when user clicks an Ignore button.
4. No - returns DialogResult.No, when user clicks a No button.
5. None - returns nothing and the dialog box continues running.
6. OK - returns DialogResult.OK, when user clicks an OK button.
7. Retry - returns DialogResult.Retry, when user clicks a Retry button.
8. Yes - returns DialogResult.Yes, when user clicks a Yes button.
Commonly Used Dialog Box Controls
1. OpenFileDialog.
2. SaveFileDialog.
3. FontDialog.
4. ColorDialog.
5. PrintDialog.
6. PrintPreviewDialog.
Displaying a Windows Common Dialog Box
Use ShowDialog method to display the common dialog box at run time. ShowDialog only displays the dialog, it does not do anything else.
Using the Information from the Dialog Box
Code must be written to retrieve and use the choice made by the user in the common dialog box. For example: the Color Dialog is displayed, the user selects a color and clicks OK. Code must then be written to apply the selected color to the object(s). To write information in the dialog box we must write code.
The following table explains the controls and their descriptions.
| S.N | Control | Description |
|---|---|---|
| 1 | ColorDialog | It represents a common dialog box that displays available colors along with controls that enable the user to define custom colors. |
| 2 | FontDialog | It prompts the user to choose a font from among those installed on the local computer and lets the user select the font, font size, and color. |
| 3 | OpenFileDialog | It prompts the user to open a file and allows the user to select a file to open. |
| 4 | SaveFileDialog | It prompts the user to select a location for saving a file and allows the user to specify the name of the file to save data. |
| 5 | PrintDialog | It lets the user print documents by selecting a printer and choosing which section of the document to print from a Windows Forms application. |
Setting Initial Values
Setting the initial value is done before executing the dialog box, for example:
FontDialog1.Font = subTotalLabel.Font ColorDialog1.Color = Me.BackColor
It should be the user defined value. Before executing the ShowDialog method, assign the existing values of the object's properties that will be altered. When the dialog box appears, the current values will be selected. If the user presses Cancel, property settings for the objects will remain unchanged.
Free study material for Computer Science
Free CBSE Study Guides: Computer Science .NET Technology
Essential Notes for Computer Science
Review targeted study resources for .NET Technology tailored for learners. Utilizing these structured notes and quick-revision tools ensures complete alignment with current CBSE evaluation standards.
Verified Solutions for Computer Science
Each resource draws directly from authorized textbooks to maintain academic accuracy. Evaluating solved examples allows students to master the formal presentation and answer-writing standards expected in upcoming school exams.
Enhance Accuracy with Online Tests
Wrap up your chapter revision by testing your knowledge against standard objective question formats. Explore our full library of free, up-to-date sample papers and online assessments to secure top grades in your CBSE examinations.
FAQs
The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.
Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.
Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.
in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.
All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.
Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.