How To Delete a File in VB.NET
In this article I describe how to delete a file using VB.NET.
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.
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: