Donate SIGN UP

Visual Basic Help Please - Deleting A Selected File

Avatar Image
xAsh | 14:43 Tue 21st Oct 2008 | Technology
6 Answers
Hello hope everyone is well.

I've created a form with buttons and text boxes, with the buttons browsing, saving or opening a file, for example after a file has been opened, the browse button will open the contents and display it in the text box.

However, how would i go about deleting the selected file from my area? I mean can someone give me or start me off on the code please as i've been searching for ages.

Many thanks
Gravatar

Answers

1 to 6 of 6rss feed

Best Answer

No best answer has yet been selected by xAsh. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
Which version of VB are you using?
Question Author
Hey man, am using Visual Studio 2005.
Hi xAsh,

Been away. Will this help you get started?

Help, Index, under File.Delete method gives this example

Imports System
Imports System.IO
Imports System.Text

Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Try
Dim sw As StreamWriter = File.CreateText(path)
sw.Close()
Dim path2 As String = path + "temp"

' Ensure that the target does not exist.
File.Delete(path2)

' Copy the file.
File.Copy(path, path2)
Console.WriteLine("{0} was copied to {1}.", path, path2)

' Delete the newly created file.
File.Delete(path2)
Console.WriteLine("{0} was successfully deleted.", path2)

Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
PS. I get a lot of help (and regular emails of articles) from here:-

http://visualbasic.about.com/od/usingvbnet/a/w pfintro6.htm?nl=1
Question Author
that's great man, thanks a lot for your reply! :)
Did it work?

1 to 6 of 6rss feed

Do you know the answer?

Visual Basic Help Please - Deleting A Selected File

Answer Question >>

Related Questions

Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.