Solved

delete file using vb.net

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert datetime to time string 10 34
DataGridView / get bound table name? 8 36
vb.net datagrid scroll automatically to the first found row 11 28
Need help with a query 14 37
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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