How to delete a file using VB.NET?

This one doesn't require so much mystery :)

My.Computer.FileSystem.DeleteFile(ADDRESS_OF_FILE_AS_STRING)

Deleting a file is quite simple - but dangerous! So be very careful when you're trying out this code. Make sure the file you're going to delete is not needed - you won't be able to restore it from the recycle bin!

To delete a file from your computer, you use the Delete method of System.IO. Here's some new code for you to try:

Dim FileToDelete As String

FileToDelete = "C:\Users\Owner\Documents\testDelete.txt"

If System.IO.File.Exists( FileToDelete ) = True Then

System.IO.File.Delete( FileToDelete )
MsgBox("File Deleted")

End If

Tags:

Vb.Net