File in use after appending tif page

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
philip.y
Posts: 12
Joined: Tue May 31, 2011 11:09 pm

File in use after appending tif page

Post 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?
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: File in use after appending tif page

Post 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
philip.y
Posts: 12
Joined: Tue May 31, 2011 11:09 pm

Re: File in use after appending tif page

Post by philip.y »

Alex,

Great - works a treat thanks!

Phil
Post Reply