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 » Tue May 31, 2011 11:21 pm

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: 1445
Joined: Thu Jul 10, 2008 2:21 pm

Re: File in use after appending tif page

Post by Alex » Wed Jun 01, 2011 10:43 am

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 » Wed Jun 01, 2011 5:44 pm

Alex,

Great - works a treat thanks!

Phil

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest