How To Delete a File in VB.NET

In this article I describe how to delete a file using VB.NET.
  • 2341

Delete a File in VB.NET

The Delete method deletes the specified file permanently.

Example:

Suppose you want to delete a file at location C:\Temp\Data\MaheshTXMoved.txt.

delete-file-in-vb.net.jpg

The following code snippet deletes a file

Imports System.Text

Imports System.IO

Module Module1

    Sub Main()

        Dim fileName As String = "C:\Temp\Data\MaheshTXMoved.txt"

        Dim fi As New IO.FileInfo(fileName)

        Try

            fi.Delete()

        Catch iox As IOException

            Console.WriteLine(iox.Message)

        End Try

    End Sub

End Module

Output:

 File-Deleted-in-vb.net.jpg

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.