0
Answer

delete and upload files in database and images in folder

Danie Grey

Danie Grey

12y
959
1
Hi, I am currently working on a project where I have to upload images in a folder and upload it's corresponding information like order_number, VehicleID, etc in the database. Can anybody please provide me a code where I could do all of this? Also, how can I delete the images stored in the folder using vb.net code? P.S. I am a new to vb.net programming. Thank you with all the help you can provide.

'the code to delete image in the folder

Private Sub PictureBox11_DoubleClick(sender As System.Object, e As System.EventArgs) Handles PictureBox11.DoubleClick
        Try
            If imagelocationFromPicboxes(10).Equals(newImagePath(10)) Then
                My.Computer.FileSystem.DeleteFile(newImagePath(10))
            End If
            PictureBox11.Image = Nothing

        Catch ex As Exception
        End Try
    End Sub

'Code where I can save the image in a folder
'I also need to upload the idvehicle, ordernumber idimage in tables in the  database

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            Dim i As Integer = 0
            Dim counter As Integer = 1
            Dim fileName As String
            'Dim idVehicle As Integer
            Dim newPath As String

            i = 0
            While i < 25
                If Not String.IsNullOrEmpty(imagelocationFromPicboxes(i)) Then
                    fileName = Path.GetFileName(imagelocationFromPicboxes(i))
                    newPath = strBasePath + fileName
                    If File.Exists(newImagePath(counter - 1)) = True Then
                        My.Computer.FileSystem.DeleteFile(newImagePath(counter - 1))
                    End If
                    My.Computer.FileSystem.CopyFile(imagelocationFromPicboxes(i), newPath)
                    newFileName = "0000000001" + "_00" + counter.ToString() + Path.GetExtension(imagelocationFromPicboxes(i))
                    My.Computer.FileSystem.RenameFile(newPath, newFileName)
                    imagelocationFromPicboxes(i) = newImagePath(counter - 1)
                    counter = counter + 1
                End If
                i = i + 1
            End While
            MessageBox.Show("Image/s uploaded!")
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try