?
Solved

delete file using vb.net

Posted on 2004-08-31
4
Medium Priority
?
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 600 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 86

Accepted Solution

by:
Mike Tomlinson earned 900 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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