Solved

delete file using vb.net

Posted on 2004-08-31
4
258 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now