alexa
menu

    Show / Hide Table of Contents

    Class SaveOptions

    Represents the options for customizing the behavior while saving a Markdown document.

    Inheritance
    System.Object
    SaveOptions
    Namespace: Syncfusion.Office.Markdown
    Assembly: Syncfusion.Markdown.dll
    Syntax
    public class SaveOptions : Object
    Examples

    The following example demonstrates how to use SaveOptions to handle image nodes while saving a Markdown document and save images to a local folder:

    // Creates a new MarkdownDocument instance
    MarkdownDocument markdownDocument = new MarkdownDocument();
    // Subscribes the SaveImage handler to process image nodes during saving
    markdownDocument.SaveOptions.ImageNodeVisited += SaveImage;
    // Saves the markdown document to a file stream
    using (FileStream outputStream = new FileStream("Output.md", FileMode.Create, FileAccess.Write))
        markdownDocument.Save(outputStream);
    // Unsubscribes the SaveImage handler after the document has been saved
    markdownDocument.SaveOptions.ImageNodeVisited -= SaveImage;
    // Disposes the document
    markdownDocument.Dispose();
    
    private void SaveImage(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
    {
        string imagePath = @"D:\Temp\" + "Image_" + Guid.NewGuid().ToString() + ".png";
        // Save the image stream to a local file
        using (FileStream fileStreamOutput = File.Create(imagePath))
            args.ImageStream.CopyTo(fileStreamOutput);
        // Set the URI to be used for the image in the output Markdown
        args.Uri = imagePath;
    }
    ' Creates a new MarkdownDocument instance
    Dim markdownDocument As New MarkdownDocument()
    ' Subscribes the SaveImage handler
    AddHandler markdownDocument.SaveOptions.ImageNodeVisited, AddressOf SaveImage
    ' Saves the markdown document to a file stream
    Using outputStream As New FileStream("Output.md", FileMode.Create, FileAccess.Write)
        markdownDocument.Save(outputStream)
    End Using
    ' Unsubscribes after use
    RemoveHandler markdownDocument.SaveOptions.ImageNodeVisited, AddressOf SaveImage
    ' Disposes the document
    markdownDocument.Dispose()
    
    Private Sub SaveImage(sender As Object, args As Syncfusion.Office.Markdown.SaveImageNodeVisitedEventArgs)
        Dim imagePath As String = "D:\Temp\Image_" & Guid.NewGuid().ToString() & ".png"
        ' Save the image stream to a local file
        Using fileStreamOutput As FileStream = File.Create(imagePath)
            args.ImageStream.CopyTo(fileStreamOutput)
        End Using
        ' Set the URI to be used for the image in the output Markdown
        args.Uri = imagePath
    End Sub

    Constructors

    SaveOptions()

    Declaration
    public SaveOptions()

    Properties

    Encoding

    Gets or sets the text encoding to use when saving Markdown documents. Default value is UTF8 (without BOM - Byte Order Mark).

    Declaration
    public Encoding Encoding { get; set; }
    Property Value
    Type
    System.Text.Encoding

    Methods

    add_ImageNodeVisited(SaveImageNodeVisitedEventHandler)

    Declaration
    public void add_ImageNodeVisited(SaveImageNodeVisitedEventHandler value)
    Parameters
    Type Name Description
    SaveImageNodeVisitedEventHandler value

    remove_ImageNodeVisited(SaveImageNodeVisitedEventHandler)

    Declaration
    public void remove_ImageNodeVisited(SaveImageNodeVisitedEventHandler value)
    Parameters
    Type Name Description
    SaveImageNodeVisitedEventHandler value

    Events

    ImageNodeVisited

    Occurs during Markdown saving when an image node is encountered. Use this event to save the image externally and customize the image URI written to the Markdown output.

    Declaration
    public event SaveImageNodeVisitedEventHandler ImageNodeVisited
    Event Type
    Type
    SaveImageNodeVisitedEventHandler
    Remarks

    When this event is subscribed to, the image is not embedded as Base64 in the Markdown output. Instead, the value assigned to Uri within the event handler is used as the image path in the Markdown file.

    Examples

    The following example demonstrates how to use the ImageNodeVisited event to save image files locally and set their paths in the output Markdown:

    private void SaveImage(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
    {
        string imagePath = @"D:\Temp\" + "Image_" + Guid.NewGuid().ToString() + ".png";
        // Save the image stream to a local file
        using (FileStream fileStreamOutput = File.Create(imagePath))
            args.ImageStream.CopyTo(fileStreamOutput);
        // Set the URI to be used for the image in the output Markdown
        args.Uri = imagePath;
    }
    Private Sub SaveImage(sender As Object, args As Syncfusion.Office.Markdown.SaveImageNodeVisitedEventArgs)
        Dim imagePath As String = "D:\Temp\Image_" & Guid.NewGuid().ToString() & ".png"
        Using fileStreamOutput As FileStream = File.Create(imagePath)
            args.ImageStream.CopyTo(fileStreamOutput)
        End Using
        args.Uri = imagePath
    End Sub
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved