DocumentOriginalFileName Property
Gets the original file name of the document.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 18.12
Syntax
public string OriginalFileName { get; }

Property Value

Type: String
Remarks

Returns null if the document was loaded from a stream or created blank.

Examples
Shows how to retrieve the details of the path, filename and LoadFormat of a document from when the document was first loaded into memory.
[C#]

Document doc = new Document(MyDir + "Document.doc");

// This property will return the full path and file name where the document was loaded from.
String originalFilePath = doc.OriginalFileName;
// Let's get just the file name from the full path.
String originalFileName = Path.GetFileName(originalFilePath);

// This is the original LoadFormat of the document.
LoadFormat loadFormat = doc.OriginalLoadFormat;
Examples
Shows how to use the FileFormatUtil methods to detect the format of a document without any extension and save it with the correct file extension.
[C#]

// Load the document without a file extension into a stream and use the DetectFileFormat method to detect it's format. 
// These are both times where you might need extract the file format as it's not visible
FileStream
    docStream = File.OpenRead(
        MyDir + "Document.FileWithoutExtension"); // The file format of this document is actually ".doc"
FileFormatInfo info = FileFormatUtil.DetectFileFormat(docStream);

// Retrieve the LoadFormat of the document.
LoadFormat loadFormat = info.LoadFormat;

// Let's show the different methods of converting LoadFormat enumerations to SaveFormat enumerations.
// 
// Method #1
// Convert the LoadFormat to a String first for working with. The String will include the leading dot in front of the extension.
String fileExtension = FileFormatUtil.LoadFormatToExtension(loadFormat);
// Now convert this extension into the corresponding SaveFormat enumeration
SaveFormat saveFormat = FileFormatUtil.ExtensionToSaveFormat(fileExtension);

// Method #2
// Convert the LoadFormat enumeration directly to the SaveFormat enumeration.
saveFormat = FileFormatUtil.LoadFormatToSaveFormat(loadFormat);

// Load a document from the stream.
Document doc = new Document(docStream);

// Save the document with the original file name, " Out" and the document's file extension.
doc.Save(
    MyDir + @"\Artifacts\Document.WithFileExtension" + FileFormatUtil.SaveFormatToExtension(saveFormat));
See Also