Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a file using VB.NET?

Tags:

vb.net

I have a button in my program that will delete a certain file when clicked, such as example.txt. The code I have to delete it is:

File.Delete("example.txt")

But the file is still there. I have done some research and most people say that it should work. Why is this not working? Or is this code wrong?

like image 866
ShaneRibz Avatar asked Jan 19 '14 17:01

ShaneRibz


People also ask

How do you delete in VB?

To delete a text file and ask the user to confirm that the file should be deleted. Use the DeleteFile method to delete the file, setting showUI to AllDialogs . The following code demonstrates how to delete the file named test. txt and allow the user to confirm that the file should be deleted.

How do I delete a file in VBA?

In VBA, we can delete any file present in the computer using VBA codes. The code used to delete files is known as the “Kill” command. The method to delete any file is that first, we must provide the file's path, which means the file's location on the computer. Then, we use the “Kill” command to delete the file.


1 Answers

This one doesn't require so much mystery :)

My.Computer.FileSystem.DeleteFile(ADDRESS_OF_FILE_AS_STRING)
like image 137
Daniel Charry Avatar answered Oct 02 '22 22:10

Daniel Charry