Free Support Forum - aspose.com

HeaderFooter and Range.UpdateFields in VB.Net

Can you kindly convert the following code to VB.NET. It is code that you previously provided in C#.Net regarding using Range.UpdateFields() and HeaderFooters.

private void UpdateMyTemplateFile(string sFileName)

{

Aspose.Words.Document myWordDocument = new Aspose.Words.Document(sFileName);

for(int iSection = 0 ; iSection < myWordDocument.Sections.Count ; iSection++)

{

myWordDocument.Sections[iSection].HeadersFooters[Aspose.Words.HeaderFooterType.FooterEven].Range.UpdateFields();

myWordDocument.Sections[iSection].HeadersFooters[Aspose.Words.HeaderFooterType.FooterFirst].Range.UpdateFields();

myWordDocument.Sections[iSection].HeadersFooters[Aspose.Words.HeaderFooterType.FooterPrimary].Range.UpdateFields();

}

myWordDocument.Save(sFileName);

}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Here is code in VB.NET.

Private Sub UpdateMyTemplateFile(ByVal sFileName As String)

Dim myWordDocument As Aspose.Words.Document = New Aspose.Words.Document(sFileName)

Dim iSection As Integer

For iSection = 0 To myWordDocument.Sections.Count - 1

myWordDocument.Sections(iSection).HeadersFooters(Aspose.Words.HeaderFooterType.FooterEven).Range.UpdateFields()

myWordDocument.Sections(iSection).HeadersFooters(Aspose.Words.HeaderFooterType.FooterFirst).Range.UpdateFields()

myWordDocument.Sections(iSection).HeadersFooters(Aspose.Words.HeaderFooterType.FooterPrimary).Range.UpdateFields()

Next

myWordDocument.Save(sFileName)

End Sub

But note, at the moment Aspose.Words updates the results of DOCPROPERTY and DOCVARIABLE fields only.

Best regards.