public class FieldFileName extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the name of the current document from its storage location.
In the current implementation, uses the Document.getOriginalFileName() property to retrieve the file name. If the document was loaded from a stream or created blank, uses the name of the file that is being saved to (if known).
Examples:
Shows how to use FieldOptions to override the default value for the FILENAME field.
Document doc = new Document(getMyDir() + "Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.writeln();
// This FILENAME field will display the local system file name of the document we loaded.
FieldFileName field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.update();
Assert.assertEquals(" FILENAME ", field.getFieldCode());
Assert.assertEquals("Document.docx", field.getResult());
builder.writeln();
// By default, the FILENAME field shows the file's name, but not its full local file system path.
// We can set a flag to make it show the full file path.
field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.setIncludeFullPath(true);
field.update();
Assert.assertEquals(getMyDir() + "Document.docx", field.getResult());
// We can also set a value for this property to
// override the value that the FILENAME field displays.
doc.getFieldOptions().setFileName("FieldOptions.FILENAME.docx");
field.update();
Assert.assertEquals(" FILENAME \\p", field.getFieldCode());
Assert.assertEquals("FieldOptions.FILENAME.docx", field.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + doc.getFieldOptions().getFileName());
| Modifier and Type | Method and Description |
|---|---|
boolean |
getIncludeFullPath()
Gets whether to include the full file path name.
|
int |
getSwitchType(java.lang.String switchName) |
void |
setIncludeFullPath(boolean value)
Sets whether to include the full file path name.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic boolean getIncludeFullPath()
Examples:
Shows how to use FieldOptions to override the default value for the FILENAME field.
Document doc = new Document(getMyDir() + "Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.writeln();
// This FILENAME field will display the local system file name of the document we loaded.
FieldFileName field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.update();
Assert.assertEquals(" FILENAME ", field.getFieldCode());
Assert.assertEquals("Document.docx", field.getResult());
builder.writeln();
// By default, the FILENAME field shows the file's name, but not its full local file system path.
// We can set a flag to make it show the full file path.
field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.setIncludeFullPath(true);
field.update();
Assert.assertEquals(getMyDir() + "Document.docx", field.getResult());
// We can also set a value for this property to
// override the value that the FILENAME field displays.
doc.getFieldOptions().setFileName("FieldOptions.FILENAME.docx");
field.update();
Assert.assertEquals(" FILENAME \\p", field.getFieldCode());
Assert.assertEquals("FieldOptions.FILENAME.docx", field.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + doc.getFieldOptions().getFileName());
public void setIncludeFullPath(boolean value)
throws java.lang.Exception
Examples:
Shows how to use FieldOptions to override the default value for the FILENAME field.
Document doc = new Document(getMyDir() + "Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.writeln();
// This FILENAME field will display the local system file name of the document we loaded.
FieldFileName field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.update();
Assert.assertEquals(" FILENAME ", field.getFieldCode());
Assert.assertEquals("Document.docx", field.getResult());
builder.writeln();
// By default, the FILENAME field shows the file's name, but not its full local file system path.
// We can set a flag to make it show the full file path.
field = (FieldFileName) builder.insertField(FieldType.FIELD_FILE_NAME, true);
field.setIncludeFullPath(true);
field.update();
Assert.assertEquals(getMyDir() + "Document.docx", field.getResult());
// We can also set a value for this property to
// override the value that the FILENAME field displays.
doc.getFieldOptions().setFileName("FieldOptions.FILENAME.docx");
field.update();
Assert.assertEquals(" FILENAME \\p", field.getFieldCode());
Assert.assertEquals("FieldOptions.FILENAME.docx", field.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + doc.getFieldOptions().getFileName());
value - Whether to include the full file path name.java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)