Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The process cannot access the file

Status
Not open for further replies.

scottsanpedro

Programmer
Apr 26, 2002
97
0
0
GB
HI all. I am a little stuck on a peocedure.
I'm trying to move files once they have been imported into SQL Server. The first file moves correctly, then I get the above error.
I know it's something to do with dispose or close but can't get my head around it. Here is the code so far, the main part I am having trouble with is the last section.
Code:
Public Sub ImportCSVStockData()

        Dim path As String
        Dim targetPath As String

        Try

            For Each MyFile In Directory.GetFiles("C:\PRC\Projects\")
                Dim data = From line In File.ReadAllLines(MyFile.ToString)
                        Let parts = line.Split(",")
                        Select New With {
                            .location = parts(0),
                            .barcode = parts(1),
                            .qty = parts(2)}


                For Each Valx In data
                    Dim tbl As New tblScannedImport With {
                        .Location = Valx.location,
                        .BarCode = Valx.barcode,
                        .Quantity = Valx.qty,
                        .FileName = MyFile.Substring(16, Len(MyFile) - 16),
                        .DateAdded = Now}
                    dbx.tblScannedImports.AddObject(tbl)
                Next
                dbx.SaveChanges()

                path = "C:\PRC\Projects\" & MyFile.Substring(16, Len(MyFile) - 16)
                targetPath = "C:\PRC\Projects\Saved Files\" & MyFile.Substring(16, Len(MyFile) - 16)

                If File.Exists(targetPath) Then
                    File.Delete(targetPath)
                End If

                File.Move(path, targetPath)

            Next
        Catch ex As Exception
            clsNotes.MainErrorCall(ex.Message, ex.Source)
        End Try

    End Sub
thanks for any help. Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top