[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
  • 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
  • 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!

1 comment:

  1. My brother suggested I might like this website. He was totally right. This submit truly made my day. You cann't imagine simply how so much time I had spent for this information! Thanks! paypal login