Support Forums
[TuToRiAl] How to Delete a file in Visual Basic - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [TuToRiAl] How to Delete a file in Visual Basic (/showthread.php?tid=12466)



[TuToRiAl] How to Delete a file in Visual Basic - Resistance - 10-04-2010

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



RE: [TuToRiAl] How to Delete a file in Visual Basic - Shirosaki. - 10-05-2010

Thanks a lot mate, very useful !