Solved

delete file using vb.net

Posted on 2004-08-31
4
261 Views
Last Modified: 2010-04-23
hi all,

i created a vb.net app..
the app is able to read file..
however i want to add in the delete file function..
any idea on how to delete a file using the VB.NET app?

0
Comment
Question by:TPoly
4 Comments
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 200 total points
ID: 11949059
Private Sub DeleteLogFile()
        Dim path As String
        Dim endIndex As Integer

        path = [Assembly].GetExecutingAssembly.Location()
        endIndex = path.LastIndexOf("\")
        path = path.Substring(0, endIndex)

        If File.Exists(path + NAVIGATION_FILE) Then
            File.Delete(path + NAVIGATION_FILE)
        End If
    End Sub

Where NAVIGATION_FILE is the name of the file
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 11949213
You should place the delete call in a Try...Catch so if it fails you can display a message explaining why (hopefully):

    Private Sub deleteFile(ByVal fileName As String)
        If System.IO.File.Exists(fileName) Then
            Try
                System.IO.File.Delete(fileName)
            Catch ex As Exception
                MsgBox(fileName & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "Unable to delete file")
            End Try
        Else
            MsgBox(fileName, MsgBoxStyle.Critical, "File does not exist")
        End If
    End Sub

Idle_Mind
0
 
LVL 5

Expert Comment

by:thenrich
ID: 11951365
Kill(filename)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11952027
Aaah, yes, a lot of VB6 code still does work in VB.NET *GRIN*

Bob
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question