Member Avatar for hueikar

I would like to do a coding to delete the txt.file that i had created before using visual studio..can anyone teach me the coding?thank you.

Recommended Answers

All 14 Replies

Have a look at this link with some sample code Here.

Member Avatar for hueikar

thank you for the reply.but i mean is using visual studio(basic)to delete the file.and also i want to delete file that will choose by user,not the fix one txt file.thank you.

Are you using VB6 or VB.Net?

Member Avatar for hueikar

i am using visual studio 2010 doing the visual basic.

Download the sample application Here.

This will load all files explorer style. Now use the code in the link I supplied earlier on to delete a selected file.:)

Member Avatar for hueikar

Thank you.but how can i join the both coding?the sample application gt so many form n coding inside..and is it the sample use for searching the folder?if i use open file dialog can delete the file?

imports system.io

file.delete("pathtofile.txt")

Open file dialog will not work. With the link above, using explorer style, the user can load files and by clicking on a file, the path is returned. This way you can now delete the file as in -

Dim FileToDelete As String

FileToDelete = "C:\Users\Owner\Documents\testDelete.txt"

If System.IO.File.Exists(FileToDelete) = True Then

System.IO.File.Delete(FileToDelete)
MsgBox("File Deleted")

End If

if i understand what you are asking you can deleter the file with using an open file dialog..

OpenFileDialog1.ShowDialog()

Dim FilePath as String = OpenFileDialog1.Filename

File.Delete(FilePath)

Just use AndreW's Code In The Middle To Be Sure That The File Exists.

Member Avatar for hueikar

Open file dialog will not work. With the link above, using explorer style, the user can load files and by clicking on a file, the path is returned. This way you can now delete the file as in -

Dim FileToDelete As String

FileToDelete = "C:\Users\Owner\Documents\testDelete.txt"

If System.IO.File.Exists(FileToDelete) = True Then

System.IO.File.Delete(FileToDelete)
MsgBox("File Deleted")

End If

thank you.i directly copy ur coding inside my project, but the button delete didnt work anything.

Member Avatar for hueikar

if i understand what you are asking you can deleter the file with using an open file dialog..

OpenFileDialog1.ShowDialog()

Dim FilePath as String = OpenFileDialog1.Filename

File.Delete(FilePath)

Just use AndreW's Code In The Middle To Be Sure That The File Exists.

thank you.it really work.but can the file i want to delete will go to recycle bin?

Yes, it will be added to the recycle bin.

If you want to clear the recycle bin, try the following -

Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias
"SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String,
ByVal dwFlags As Int32) As Int32
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As
Int32

Private Const SHERB_NOCONFIRMATION = &H1
Private Const SHERB_NOPROGRESSUI = &H2
Private Const SHERB_NOSOUND = &H4

#Region "Empty Recycle Bin (SUB)"

Private Sub EmptyRecycleBin()
SHEmptyRecycleBin(Me.Handle.ToInt32, vbNullString, SHERB_NOCONFIRMATION +
SHERB_NOSOUND)
SHUpdateRecycleBinIcon()
End Sub

#End Region
Member Avatar for hueikar

Yes, it will be added to the recycle bin.

If you want to clear the recycle bin, try the following -

Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias
"SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String,
ByVal dwFlags As Int32) As Int32
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As
Int32

Private Const SHERB_NOCONFIRMATION = &H1
Private Const SHERB_NOPROGRESSUI = &H2
Private Const SHERB_NOSOUND = &H4

#Region "Empty Recycle Bin (SUB)"

Private Sub EmptyRecycleBin()
SHEmptyRecycleBin(Me.Handle.ToInt32, vbNullString, SHERB_NOCONFIRMATION +
SHERB_NOSOUND)
SHUpdateRecycleBinIcon()
End Sub

#End Region

nope.the coding u given before this post is straightly delete the file.cant find it in recycle bin..thank you.

commented: For not giving up on trying until it works. +4

It was a pleasure. Please mark as solved if there are no more questions regarding the deletion of a text file, thanks.:)

I gave you some rep points for trying until it works, well done!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.