Attaching/changing template in document

I read a post that said this was possible but I cannot get it to work....

I have tried to change the template in the word documents using the demo version 3.4 of your API with no success. Am I missing something? We really need this tool to fix thousands of word documents that have old server names in them - they take a long time to open because it cannot find the server. What am I missing?

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

ofd.ShowDialog()

Dim docName As String = ofd.FileName

If docName <> Nothing AndAlso docName.Length > 0 Then

Dim etime As DateTime = Now

Dim doc As New Document(docName)

doc.Unprotect()

Dim tempPath As String = doc.BuiltInDocumentProperties.Template

tempPath = IO.Path.GetDirectoryName(tempPath)

tempPath = IO.Path.Combine(tempPath, "Normal.dot")

doc.BuiltInDocumentProperties.Template = tempPath

Dim fPath As String = IO.Path.GetDirectoryName(docName)

Dim fName As String = "new" & IO.Path.GetFileName(docName)

doc.Save(IO.Path.Combine(fPath, fName))

Debug.WriteLine("Elapsed time: " & Now.Subtract(etime).Seconds & " seconds")

End If

End Sub

As far as I can see your code should work ok. Try to move Debug.WriteLine up to find out where exactly does the delay occur.

Also, if you attach a sample document I can help you further.

Do I need the full version for this to work? I currently only have the demo.

Evaluation version of Aspose.Word is fully functional. I'll make a quick research on your document and inform you of the results tomorrow.

Indeed, it does not work. We are planning to fix it in the next release.

Meanwhile, as a workaround, you can use ImportNode method to move all contents of your documents to brand new documents with no invalid template references.

Thanks for the rapid response. I will give the workaround a try. As far as the next release is concerned, any idea about when that might be available?

Next release is planned on the end of January.

The Document.BuiltInDocumentProperties.Template property is for information purposes only. We've now added a comment into the API documentation on this.

If you want to change the document template - use the Document.AttachedTemplate property.