PageSavingArgsKeepPageStreamOpen Property

Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public bool KeepPageStreamOpen { get; set; }

Property Value

Type: Boolean
Remarks

Default is false and Aspose.Words will close the stream you provided in the PageStream property after writing a document page into it. Specify true to keep the stream open.

Examples
Shows how separate pages are saved when a document is exported to fixed page format.
public void PageFileName()
{
    Document doc = new Document(MyDir + "Rendering.docx");

    HtmlFixedSaveOptions htmlFixedSaveOptions =
        new HtmlFixedSaveOptions { PageIndex = 0, PageCount = doc.PageCount };
    htmlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

    doc.Save($"{ArtifactsDir}SavingCallback.PageFileName.html", htmlFixedSaveOptions);

    string[] filePaths = Directory.GetFiles(ArtifactsDir, "SavingCallback.PageFileName.Page_*.html");

    for (int i = 0; i < doc.PageCount; i++)
    {
        string file = $"{ArtifactsDir}SavingCallback.PageFileName.Page_{i}.html";
    }
}

/// <summary>
/// Custom PageFileName is specified.
/// </summary>
private class CustomPageFileNamePageSavingCallback : IPageSavingCallback
{
    public void PageSaving(PageSavingArgs args)
    {
        string outFileName = $"{ArtifactsDir}SavingCallback.PageFileName.Page_{args.PageIndex}.html";

        // Specify name of the output file for the current page either in this 
        args.PageFileName = outFileName;

        // ..or by setting up a custom stream
        args.PageStream = new FileStream(outFileName, FileMode.Create);
        Assert.False(args.KeepPageStreamOpen);
    }
}
See Also