VB.Net Delete File

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

Kill("c:\Pilot\Pilot_2007.adp")

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?
martgriffAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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

0
 
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
            Kill("c:\Pilot\Pilot_2007.adp")
        End If

Open in new window

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

From novice to tech pro — start learning today.