Solved

delete file using vb.net

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form design in vb.net 7 34
Getfiles in vb.net 28 42
Saveas need to save a copy 16 26
Open a word document 23 33
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

14 Experts available now in Live!

Get 1:1 Help Now