Aspose::Words::Fields::FieldFileSize Class Reference

Detailed Description

Implements the FILESIZE field.

Retrieves the size of the current document's file or 0 if the size cannot be determined.

In the current implementation, uses the OriginalFileName property to retrieve the file name used to determine the file size.

Examples

Shows how to display the file size of a document with a FILESIZE field.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
ASSERT_EQ(18105, doc->get_BuiltInDocumentProperties()->get_Bytes());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->InsertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
auto field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->Update();
ASSERT_EQ(u" FILESIZE ", field->GetFieldCode());
ASSERT_EQ(u"18105", field->get_Result());
// 2 - Kilobytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInKilobytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\k", field->GetFieldCode());
ASSERT_EQ(u"18", field->get_Result());
// 3 - Megabytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInMegabytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\m", field->GetFieldCode());
ASSERT_EQ(u"0", field->get_Result());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc->Save(ArtifactsDir + u"Field.FILESIZE.docx");

#include <Aspose.Words.Cpp/Fields/FieldFileSize.h>

+ Inheritance diagram for Aspose::Words::Fields::FieldFileSize:

Public Member Functions

bool get_IsInKilobytes ()
 Gets or sets whether to display the file size in kilobytes. More...
 
bool get_IsInMegabytes ()
 Gets or sets whether to display the file size in megabytes. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_IsInKilobytes (bool value)
 Setter for get_IsInKilobytes. More...
 
void set_IsInMegabytes (bool value)
 Setter for get_IsInMegabytes. More...
 
- Public Member Functions inherited from Field
String get_DisplayResult ()
 Gets the text that represents the displayed field result. More...
 
SharedPtr< FieldEndget_End () const
 Gets the node that represents the field end. More...
 
SharedPtr< FieldEndget_FieldEnd () const
 Gets the node that represents the field end. More...
 
SharedPtr< FieldStartget_FieldStart () const
 Gets the node that represents the start of the field. More...
 
SharedPtr< FieldFormatget_Format ()
 Gets a FieldFormat object that provides typed access to field's formatting. More...
 
bool get_IsDirty ()
 Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document. More...
 
bool get_IsLocked ()
 Gets or sets whether the field is locked (should not recalculate its result). More...
 
int32_t get_LocaleId ()
 Gets or sets the LCID of the field. More...
 
String get_Result ()
 Gets or sets text that is between the field separator and field end. More...
 
SharedPtr< FieldSeparatorget_Separator ()
 Gets the node that represents the field separator. Can be null. More...
 
SharedPtr< FieldStartget_Start () const
 Gets the node that represents the start of the field. More...
 
virtual FieldType get_Type () const
 Gets the Microsoft Word field type. More...
 
String GetFieldCode ()
 Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included. More...
 
String GetFieldCode (bool includeChildFieldCodes)
 Returns text between field start and field separator (or field end if there is no separator). More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
SharedPtr< NodeRemove ()
 Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null. More...
 
void set_IsDirty (bool value)
 Setter for get_IsDirty. More...
 
void set_IsLocked (bool value)
 Setter for get_IsLocked. More...
 
void set_LocaleId (int32_t value)
 Setter for get_LocaleId. More...
 
void set_Result (const String &value)
 Setter for get_Result. More...
 
bool Unlink ()
 Performs the field unlink. More...
 
void Update ()
 Performs the field update. Throws if the field is being updated already. More...
 
void Update (bool ignoreMergeFormat)
 Performs a field update. Throws if the field is being updated already. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from Field
static const TypeInfoType ()
 

Member Function Documentation

◆ get_IsInKilobytes()

bool Aspose::Words::Fields::FieldFileSize::get_IsInKilobytes ( )

Gets or sets whether to display the file size in kilobytes.

Examples

Shows how to display the file size of a document with a FILESIZE field.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
ASSERT_EQ(18105, doc->get_BuiltInDocumentProperties()->get_Bytes());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->InsertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
auto field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->Update();
ASSERT_EQ(u" FILESIZE ", field->GetFieldCode());
ASSERT_EQ(u"18105", field->get_Result());
// 2 - Kilobytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInKilobytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\k", field->GetFieldCode());
ASSERT_EQ(u"18", field->get_Result());
// 3 - Megabytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInMegabytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\m", field->GetFieldCode());
ASSERT_EQ(u"0", field->get_Result());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc->Save(ArtifactsDir + u"Field.FILESIZE.docx");

◆ get_IsInMegabytes()

bool Aspose::Words::Fields::FieldFileSize::get_IsInMegabytes ( )

Gets or sets whether to display the file size in megabytes.

Examples

Shows how to display the file size of a document with a FILESIZE field.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
ASSERT_EQ(18105, doc->get_BuiltInDocumentProperties()->get_Bytes());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->InsertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
auto field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->Update();
ASSERT_EQ(u" FILESIZE ", field->GetFieldCode());
ASSERT_EQ(u"18105", field->get_Result());
// 2 - Kilobytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInKilobytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\k", field->GetFieldCode());
ASSERT_EQ(u"18", field->get_Result());
// 3 - Megabytes:
builder->InsertParagraph();
field = System::DynamicCast<FieldFileSize>(builder->InsertField(FieldType::FieldFileSize, true));
field->set_IsInMegabytes(true);
field->Update();
ASSERT_EQ(u" FILESIZE \\m", field->GetFieldCode());
ASSERT_EQ(u"0", field->get_Result());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc->Save(ArtifactsDir + u"Field.FILESIZE.docx");

◆ GetType()

virtual const System::TypeInfo & Aspose::Words::Fields::FieldFileSize::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::Fields::Field.

◆ Is()

virtual bool Aspose::Words::Fields::FieldFileSize::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::Fields::Field.

◆ set_IsInKilobytes()

void Aspose::Words::Fields::FieldFileSize::set_IsInKilobytes ( bool  value)

◆ set_IsInMegabytes()

void Aspose::Words::Fields::FieldFileSize::set_IsInMegabytes ( bool  value)

◆ Type()

static const System::TypeInfo & Aspose::Words::Fields::FieldFileSize::Type ( )
static