Back to Devexpress

Presentation.BeginUpdate() Method

officefileapi-devexpress-dot-docs-dot-presentation-dot-presentation-8bb8d42a.md

latest4.2 KB
Original Source

Presentation.BeginUpdate() Method

Locks the Presentation object until the Presentation.EndUpdate method is called.

Namespace : DevExpress.Docs.Presentation

Assembly : DevExpress.Docs.Presentation.v25.2.dll

NuGet Package : DevExpress.Docs.Presentation

Declaration

csharp
public void BeginUpdate()
vb
Public Sub BeginUpdate

Remarks

Enclose your code in the BeginUpdate - EndUpdate() method calls to improve performance when you apply multiple modifications to the presentation.

Each call to BeginUpdate must be paired with the EndUpdate() call. You can use the try...finally statement to ensure EndUpdate() is called even if an exception occurs.

The following code snippet use BeginUpdate - EndUpdate() methods:

csharp
using DevExpress.Docs.Presentation;
using System.Drawing;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {

        // Create a new presentation and clear any default slides
        Presentation presentation = new Presentation();
        presentation.Slides.Clear();
        // Begin a batch update to optimize performance and prevent intermediate presentation updates
        presentation.BeginUpdate();
        try {
            for (int i = 0; i < 5000; i++) {
                Slide slide = new Slide(SlideLayoutType.Blank);
                presentation.Slides.Add(slide);
                slide.Background = new CustomSlideBackground(new SolidFill(new DevExpress.Docs.OfficeColor(Color.LightBlue)));
            }
            presentation.DocumentProperties.Author = "John Doe";
        } finally {
            // End the batch update to apply all changes
            presentation.EndUpdate();
        }
        presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides);
        presentation.ExportToPdf(new FileStream(@"D:\\exported-document.pdf", FileMode.Create));
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports System.Drawing

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())

            ' Create a new presentation and clear any default slides
            Dim presentation As Presentation = New Presentation()
            presentation.Slides.Clear()
            ' Begin a batch update to optimize performance and prevent intermediate presentation updates
            presentation.BeginUpdate()
            Try
                For i = 0 To 4999
                    Dim slide As Slide = New Slide(SlideLayoutType.Blank)
                    presentation.Slides.Add(slide)
                    slide.Background = New CustomSlideBackground(New SolidFill(New DevExpress.Docs.OfficeColor(Color.LightBlue)))
                Next
                presentation.DocumentProperties.Author = "John Doe"
            Finally
                ' End the batch update to apply all changes
                presentation.EndUpdate()
            End Try
            presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides)
            presentation.ExportToPdf(New FileStream("D:\\exported-document.pdf", FileMode.Create))
        End Sub
    End Class
End Namespace

See Also

EndUpdate()

Presentation Class

Presentation Members

DevExpress.Docs.Presentation Namespace