Aspose::Words::Saving::ResourceSavingArgs class

ResourceSavingArgs class

Provides data for the ResourceSaving() event. To learn more, visit the Save a Document documentation article.

class ResourceSavingArgs : public System::Object


get_Document() constGets the document object that is currently being saved.
get_KeepResourceStreamOpen() constSpecifies whether Aspose.Words should keep the stream open or close it after saving a resource.
get_ResourceFileName() constGets or sets the file name (without path) where the resource will be saved to.
get_ResourceFileUri() constGets or sets the uniform resource identifier (URI) used to reference the resource file from the document.
get_ResourceStream() constAllows to specify the stream where the resource will be saved to.
GetType() const override
Is(const System::TypeInfo&) const override
set_KeepResourceStreamOpen(bool)Setter for Aspose::Words::Saving::ResourceSavingArgs::get_KeepResourceStreamOpen.
set_ResourceFileName(const System::String&)Setter for Aspose::Words::Saving::ResourceSavingArgs::get_ResourceFileName.
set_ResourceFileUri(const System::String&)Setter for Aspose::Words::Saving::ResourceSavingArgs::get_ResourceFileUri.
set_ResourceStream(const System::SharedPtr<System::IO::Stream>&)Setter for Aspose::Words::Saving::ResourceSavingArgs::get_ResourceStream.
set_ResourceStream(std::basic_ostream<CharType, Traits>&)
static Type()


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.


Shows how to use a callback to track external resources created while converting a document to HTML.

void ResourceSavingCallback()
    auto doc = MakeObject<Document>(MyDir + u"Bullet points with alternative font.docx");

    auto callback = MakeObject<ExHtmlFixedSaveOptions::FontSavingCallback>();

    auto saveOptions = MakeObject<HtmlFixedSaveOptions>();

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

    std::cout << callback->GetText() << std::endl;

class FontSavingCallback : public IResourceSavingCallback
    void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
        mText->AppendLine(String::Format(u"Original document URI:\t{0}", args->get_Document()->get_OriginalFileName()));
        mText->AppendLine(String::Format(u"Resource being saved:\t{0}", args->get_ResourceFileName()));
        mText->AppendLine(String::Format(u"Full uri after saving:\t{0}\n", args->get_ResourceFileUri()));

    String GetText()
        return mText->ToString();

    FontSavingCallback() : mText(MakeObject<System::Text::StringBuilder>())

    SharedPtr<System::Text::StringBuilder> mText;

See Also