vb.netvb.net-2010system.io.fileinfo

Delete a text file from a path using "System.IO" in visual basic 2010


I have this code:

Dim WriterDay1 As New System.IO.StreamWriter("C:\Users\IOSEagle\Desktop\My Projects\Microsoft Visual Basic 2010\Form\Programes\MyAlarm\MyAlarm\RepeatDays\Monday.txt")
WriterDay1.Write(MondayCheckBox.Text)
WriterDay1.Close()

How can I delete this text file From this path?


Solution

  • You could do something like this to get the path:

    Dim fullPath as String = ((FileStream)(WriterDay1.BaseStream)).Name
    

    And then delete the file after it is closed with this:

    File.Delete(fullPath)