Top Banner
File Handling IN VB.NET BY: Ambreen Gillani
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: File handling in vb.net

File Handling IN VB.NET

BY:

Ambreen Gillani

Page 2: File handling in vb.net

File Handling in vb.net:

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.

T he 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).

Page 3: File handling in vb.net

Import Libraries for file handling:

For file handling following system libraries are included.

For stream reader and writer.

Page 4: File handling in vb.net

Interface: Interface for file handling is:

Page 5: File handling in vb.net

By clicking on browse button following dialogue box will appear.

Page 6: File handling in vb.net

The following will appear

Page 7: File handling in vb.net

Reading a file:

For reading from a file a stream writer is used

And after reading it the reading object is closed

This command reads all the contents of file to end end and displays on the

richtextbox.

Page 8: File handling in vb.net

Reading from a file (Code):

Page 9: File handling in vb.net

Writing a file:

For writing streamwriter object is used.

For writing data from rich text box

And after that the reading object is closed

Page 10: File handling in vb.net

Code:

Page 11: File handling in vb.net

Deleting a file:

For deleting a file following command is used

Stream reader and writer is not used here.

Page 12: File handling in vb.net

Deletion Code:

Page 13: File handling in vb.net

Moving a file from one location to other:

The following command is used for moving a file from one location to the

other.

Page 14: File handling in vb.net

Code:

Page 15: File handling in vb.net

Copying a file:

The following command is used for copying a file from one path to the other.

Page 16: File handling in vb.net

Code:

Page 17: File handling in vb.net

Appending a file:

Appending is as same as writing the difference is that

After that the streamwriter is closed.

Page 18: File handling in vb.net

Code:

Page 19: File handling in vb.net

Code for displaying the contents of file:

Page 20: File handling in vb.net

For opening a file:

For opening a file a file dialogue box is used

Open file dialogue box is dragged and dropped to the program.

And following code is written:

Page 21: File handling in vb.net

Thankyou for watching