VB.Net Delete File

I have a VB.Net Program which when i click a button it Deletes a file:


How can I get it to only delete the file if it exists because if the file is not there my app goes in to error?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
Even better, let's not use Kill(), since that's an 'old' function included for compatibility with vb6/vbscript:

Sub DeleteFile(ByVal FileName As String)
    If IO.File.Exists(FileName) Then IO.File.Delete(FileName)
End Sub

Open in new window

Jonez176Connect With a Mentor Commented:
Hope this helps.  I think you also need:
Imports System.IO
        Dim di As New DirectoryInfo("c:\Pilot\Pilot_2007.adp")
        If di.Exists Then
        End If

Open in new window

martgriffAuthor Commented:
Thank you for you help Guys..........
All Courses

From novice to tech pro — start learning today.