Aspose::Words::Document::get_OriginalFileName method
Contents
[
Hide
]Document::get_OriginalFileName method
Gets the original file name of the document.
System::String Aspose::Words::Document::get_OriginalFileName() const
Remarks
Returns null if the document was loaded from a stream or created blank.
Examples
Shows how to retrieve details of a document’s load operation.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Document.docx");
ASSERT_EQ(get_MyDir() + u"Document.docx", doc->get_OriginalFileName());
ASSERT_EQ(Aspose::Words::LoadFormat::Docx, doc->get_OriginalLoadFormat());
Shows how to use the FileFormatUtil methods to detect the format of a document.
// Load a document from a file that is missing a file extension, and then detect its file format.
{
System::SharedPtr<System::IO::FileStream> docStream = System::IO::File::OpenRead(get_MyDir() + u"Word document with missing file extension");
System::SharedPtr<Aspose::Words::FileFormatInfo> info = Aspose::Words::FileFormatUtil::DetectFileFormat(docStream);
Aspose::Words::LoadFormat loadFormat = info->get_LoadFormat();
ASSERT_EQ(Aspose::Words::LoadFormat::Doc, loadFormat);
// Below are two methods of converting a LoadFormat to its corresponding SaveFormat.
// 1 - Get the file extension string for the LoadFormat, then get the corresponding SaveFormat from that string:
System::String fileExtension = Aspose::Words::FileFormatUtil::LoadFormatToExtension(loadFormat);
Aspose::Words::SaveFormat saveFormat = Aspose::Words::FileFormatUtil::ExtensionToSaveFormat(fileExtension);
// 2 - Convert the LoadFormat directly to its SaveFormat:
saveFormat = Aspose::Words::FileFormatUtil::LoadFormatToSaveFormat(loadFormat);
// Load a document from the stream, and then save it to the automatically detected file extension.
auto doc = System::MakeObject<Aspose::Words::Document>(docStream);
ASSERT_EQ(u".doc", Aspose::Words::FileFormatUtil::SaveFormatToExtension(saveFormat));
doc->Save(get_ArtifactsDir() + u"File.SaveToDetectedFileFormat" + Aspose::Words::FileFormatUtil::SaveFormatToExtension(saveFormat));
}
See Also
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++