Crosswords1 min ago
Visual Basic Help Please - Deleting A Selected File
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
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
Answers
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.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
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
http://visualbasic.about.com/od/usingvbnet/a/w pfintro6.htm?nl=1
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.