Page 1 of 1

File in use after appending tif page

Posted: Tue May 31, 2011 11:21 pm
by philip.y
I'm getting a file in use when tring to delete the file I am appending. I've tried disposing the tif object but this crashes the app.


Code: Select all

  Private Function AppendPage(ByVal sourceFile As String, ByVal newPage As String) As Boolean

        Dim tif As New Vintasoft.Imaging.Codecs.Tiff.TiffFile(sourceFile)

        Try
            tif.Pages.Add(New VintasoftImage(newPage))
            tif.SaveChanges()

        Catch ex As Exception
            Throw
        End Try
        Return True

    End Function


' Subsequent delete generates the error:
IO.File.Delete(newPage)
[/color]

Any ideas?

Re: File in use after appending tif page

Posted: Wed Jun 01, 2011 10:43 am
by Alex
Hello Philip,

You need to save a reference to the VintasoftImage object and dispose this object before removing the file.

Here is correct code:

Code: Select all

Private Function AppendPage(ByVal sourceFile As String, ByVal newPage As String) As Boolean

    Using tif As New Vintasoft.Imaging.Codecs.Tiff.TiffFile(sourceFile)
        Try
            Using image As VintasoftImage = New VintasoftImage(newPage)
                tif.Pages.Add(image)
                tif.SaveChanges()
            End Using
        Catch ex As Exception
            Throw
         End Try
    End Using

    Return True

End Function
Best regards, Alexander

Re: File in use after appending tif page

Posted: Wed Jun 01, 2011 5:44 pm
by philip.y
Alex,

Great - works a treat thanks!

Phil