Sign In  Sign Up Live-Chat

Error opening template file

Last post 04-07-2008, 2:50 PM by festevez. 4 replies.
Sort Posts: Previous Next
  •  04-07-2008, 10:48 AM 121031

    Error opening template file

    We're evaluating the Aspose.Word product and it's been working great, but we have encountered an error every so often that seems as if the template file we are using is locked and can't be accessed.  Here is the exception error we are getting:

    The process cannot access the file “\Invoices\Templates\Blank.dot” because it is being used by another process.

    Here is the code that is opening the file.  It has the clone command in it because I thought this would help in keeping the template file available, but it didn't help:

    Public Class CNetAsposeWord

            Private doc As Document

     

            Private m_Bookmarks As BookmarkCollection

     

            Public Sub New()

     

            End Sub

     

     

            Public Sub CrateNewDoc_FromTemplate(ByVal FileName As String, ByVal TemplateName As String)                      

     

                Dim srcDoc As New Document

     

                srcDoc = New Document(TemplateName, LoadFormat.Doc, String.Empty)

                doc = srcDoc.Clone()

                doc.IsTemplate = False

                srcDoc = Nothing

     

            End Sub

     

            Public Sub OpenAspose_ExistingFile(ByVal fileName As String)

                doc = New Document(fileName, LoadFormat.Doc, String.Empty)

                doc.IsTemplate = False

            End Sub

     

            Public Sub Save(ByVal FileName As String)

                doc.Save(FileName)

            End Sub

     

    End Class

    Any help you can offer is greatly appreciated!

    Frank


    This message was posted using Page2Forum from Cloning a Document - Aspose.Words for .NET and Java
     
  •  04-07-2008, 11:10 AM 121034 in reply to 121031

    Re: Error opening template file

    Hi

     

    Thanks for your request. This error occurs if document is already opened by another program like MS Word or OpenOffice. Please make sure that template is not opened by another program.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  04-07-2008, 12:05 PM 121048 in reply to 121034

    Re: Error opening template file

    Alexey...thanks for the quick response.

    We are pretty sure that Word does not have the template open since the location of the newly created file is in a different location.  Is there a specific way that we should destroy the template instance in Aspose.word once we clone the document from the template file so that we can guarantee that the template is no longer in use?

     
  •  04-07-2008, 12:19 PM 121052 in reply to 121048

    Re: Error opening template file

    Thank you for additional information. Aspose.Words doesn’t use file during processing, Aspose.Words use file only during opening. As workaround you can try reading your template into stream and then use in your application. For example see the following code.

     

    Dim fileBytes As Byte() = IO.File.ReadAllBytes("template.dot")

    Dim docStream As IO.MemoryStream = New IO.MemoryStream(fileBytes)

    Dim document As Document = New Document(docStream)

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  04-07-2008, 2:50 PM 121087 in reply to 121052

    Re: Error opening template file

    ok - we will implement it and let you know

    thanks

     
View as RSS news feed in XML