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

2 comments:


  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

    ReplyDelete
  2. You can use the products menu to select loans of numerous durations. canadian mortgage calculator Affordability is usually based on your household income, personal monthly expenses along with the automatic expenses associated with running a home: property taxes plus running costs (electricity, water, etc. mortgage payment calculator canada

    ReplyDelete