Support Forums

Full Version: [TuToRiAl] How to Delete a file in Visual Basic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone. Today I will be showing you how to delete a file in Visual Basic. Very simple and short code.

First of all due to security changes between OS', the deleting files method requires Administrator Privileges.

How to delete a file the proper way.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.DeleteFile("C:\Users\John\Desktop\Test\Mountains.jpg")
    End Sub

This file is targeting the Mountains image in the test folder on the desktop.

And another way for deleting a file is called Kill. (very interesting name.)

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Kill("C:\Users\John\Desktop\Test\Mountains.jpg")
    End Sub
Thanks a lot mate, very useful !