10-04-2010, 06:18 PM
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.
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.)
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