使用vb.net中的文件名从文件夹中删除图像

使用vb.net中的文件名从文件夹中删除图像,vb.net,image,delete-file,Vb.net,Image,Delete File,我有一个备份文件夹,在加载图像时将其存储在该文件夹中。因此,当从选中列表框中删除图像时,我需要从备份文件夹中删除该图像 那我该怎么做呢 If CheckedListBox1.Items.Count = 0 Then MsgBox("Please load the images", MsgBoxStyle.Critical) Else If Thumbcontrol1.SelectedThumbnail Is Nothing Then

我有一个备份文件夹,在加载图像时将其存储在该文件夹中。因此,当从选中列表框中删除图像时,我需要从备份文件夹中删除该图像

那我该怎么做呢

 If CheckedListBox1.Items.Count = 0 Then
        MsgBox("Please load the images", MsgBoxStyle.Critical)
    Else
        If Thumbcontrol1.SelectedThumbnail Is Nothing Then
            MsgBox("Please select the thumbnail to remove", MsgBoxStyle.Information)
        Else
            CheckedListBox1.Items.Remove(CheckedListBox1.SelectedItem)
            Thumbcontrol1.RemoveSelectedThumbnail()

            If CheckedListBox1.Items.Count > 0 Then
                CheckedListBox1.SelectedIndex = CInt(index)
            End If
            If CheckedListBox1.Items.Count = 0 Then
                Thumbcontrol1.BackgroundImage = My.Resources.backimage
                frmDisplay.GCanvas1.Image = Nothing
            End If
        End If
    End If

通过提供方法的文件路径,您可以使用System.IO.File类中的方法删除文件

System.IO.File.Delete("path\to\file")

如果不详细说明示例代码对回答问题的贡献,这不是一个正确的答案
Imports System.Data.OleDb
Public Class Form2
    Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\dv.accdb;")
    Dim cm As New OleDbCommand

    Dim bytImage() As Byte


    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
        Dim dialog As New OpenFileDialog()
        dialog.Title = "Browse Picture"
        dialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG"
        If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PictureBox1.Image = Image.FromFile(dialog.FileName)
        End If
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Try
            Dim ms As New System.IO.MemoryStream
            Dim bmpImage As New Bitmap(PictureBox1.Image)

            bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            bytImage = ms.ToArray()
            ms.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        cn.Open()
        cm.Connection = cn
        cm.CommandType = CommandType.Text
        cm.CommandText = "INSERT INTO `pic1` (pic) VALUES (@image)"
        cm.Parameters.AddWithValue("@image", bytImage)
        cm.ExecuteNonQuery()
        cn.Close()
        MsgBox("Image Saved.")
    End Sub