[VB.NET] How to delete a file in VB.NET?

Today, we will learn how to delete a file using VB.NET

The Code:
Dim file As String
file = "C://file--path--here"
If System.IO.File.Exists( file ) = True Then
System.IO.File.Delete( file )
End If
Explanations:
  • Line 1: Defines the word file as a string
  • Line 2: Defines file as C://file--path--here (change to your own path)
  • Line 3-5: If the file exists, delete the file
Improvements:
  • Add a msgbox when the deletion is complete
  • Use Try...Catch to catch exception

 If you have any question, feel free to ask it below!
And don't forget to share!

0 comments:

Post a Comment