How to Delete File using VB.Net

This tutorial is all about How to Delete File using VB.Net  With this tutorial about How to Delete File using VB.NetSo let’s get started:

You can delete a file using the DeleteFile method of the My.Computer.FileSystem object. Among the options it provides are whether the deleted file should be sent to the Recycle Bin, whether the user should be asked to confirm the deletion, and what to do if the user cancels the operation.

To delete the file, use the DeleteFile method with showUI set to AllDialogs. The code below shows how to delete the file test.txt while also allowing the user to confirm that the file should be removed.

My.Computer.FileSystem.DeleteFile(“C:\test.txt”,
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently,
Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)

To delete a file, use the DeleteFile method with the recycling parameter set to SendToRecycleBin. The following code shows how to remove the test.txt file and send it to the Recycle Bin.

My.Computer.FileSystem.DeleteFile(“C:\test.txt”, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin)

  • This tutorial is a continuation of How to Copy a File using VB.Net
  • Add button from the toolbox.
  • Then add this code to the delete button.
    [vbnet]
    Dim a As String
    a = txtdestination.Text
    My.Computer.FileSystem.DeleteDirectory(a, FileIO.DeleteDirectoryOption.DeleteAllContents)
    MsgBox(“Deleted file Succesfully”)
    [/vbnet]
  • Finally Click F5 to run Program.
    Output:

If you have any comments or suggestion about on How to Delete File using VB.Net , Please Feel Free to contact our webpage.

Download How to Delete File using VB.Net Code Here

Other articles you might read also:

Leave a Comment