ResourceSavingArgs Class

Provides data for the ResourceSaving(ResourceSavingArgs) event.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.Words.SavingResourceSavingArgs

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.5.0

ExpandedSyntax

public class ResourceSavingArgs

The ResourceSavingArgs type exposes the following members.

ExpandedProperties

  NameDescription
Public propertyCode exampleDocument
Gets the document object that is currently being saved.
Public propertyCode exampleKeepResourceStreamOpen
Specifies whether Aspose.Words should keep the stream open or close it after saving a resource.
Public propertyCode exampleResourceFileName
Gets or sets the file name (without path) where the resource will be saved to.
Public propertyCode exampleResourceFileUri
Gets or sets the uniform resource identifier (URI) used to reference the resource file from the document.
Public propertyCode exampleResourceStream
Allows to specify the stream where the resource will be saved to.

ExpandedMethods

  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

ExpandedRemarks

By default, when Aspose.Words saves a document to fixed page HTML or SVG, it saves each resource into a separate file. Aspose.Words uses the document file name and a unique number to generate unique file name for each resource found in the document.

ResourceSavingArgs allows to redefine how resource file names are generated or to completely circumvent saving of resources into files by providing your own stream objects.

To apply your own logic for generating resource file names use the ResourceFileName property.

To save resources into streams instead of files, use the ResourceStream property.

ExpandedExamples

Shows how to use a callback to track external resources created while converting a document to HTML.
public void ResourceSavingCallback()
{
    Document doc = new Document(MyDir + "Bullet points with alternative font.docx");

    FontSavingCallback callback = new FontSavingCallback();

    HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions
    {
        ResourceSavingCallback = callback
    };

    doc.Save(ArtifactsDir + "HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

    Console.WriteLine(callback.GetText());
}

private class FontSavingCallback : IResourceSavingCallback
{
    /// <summary>
    /// Called when Aspose.Words saves an external resource to fixed page HTML or SVG.
    /// </summary>
    public void ResourceSaving(ResourceSavingArgs args)
    {
        mText.AppendLine($"Original document URI:\t{args.Document.OriginalFileName}");
        mText.AppendLine($"Resource being saved:\t{args.ResourceFileName}");
        mText.AppendLine($"Full uri after saving:\t{args.ResourceFileUri}\n");
    }

    public string GetText()
    {
        return mText.ToString();
    }

    private readonly StringBuilder mText = new StringBuilder();
}

ExpandedSee Also