コード例 #1
0
        public void FileName()
        {
            //ExStart
            //ExFor:FieldOptions.FileName
            //ExFor:FieldFileName
            //ExFor:FieldFileName.IncludeFullPath
            //ExSummary:Shows how to use FieldOptions to override the default value for the FILENAME field.
            Document        doc     = new Document(MyDir + "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.FieldFileName, true);

            field.Update();

            Assert.AreEqual(" FILENAME ", field.GetFieldCode());
            Assert.AreEqual("Document.docx", field.Result);

            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.FieldFileName, true);
            field.IncludeFullPath = true;
            field.Update();

            Assert.AreEqual(MyDir + "Document.docx", field.Result);

            // We can also set a value for this property to
            // override the value that the FILENAME field displays.
            doc.FieldOptions.FileName = "FieldOptions.FILENAME.docx";
            field.Update();

            Assert.AreEqual(" FILENAME  \\p", field.GetFieldCode());
            Assert.AreEqual("FieldOptions.FILENAME.docx", field.Result);

            doc.UpdateFields();
            doc.Save(ArtifactsDir + doc.FieldOptions.FileName);
            //ExEnd

            doc = new Document(ArtifactsDir + "FieldOptions.FILENAME.docx");

            Assert.IsNull(doc.FieldOptions.FileName);
            TestUtil.VerifyField(FieldType.FieldFileName, " FILENAME ", "FieldOptions.FILENAME.docx", doc.Range.Fields[0]);
        }
コード例 #2
0
        public void FieldOptionsFileName()
        {
            //ExStart
            //ExFor:FieldOptions.FileName
            //ExFor:FieldFileName
            //ExFor:FieldFileName.IncludeFullPath
            //ExSummary:Shows how to use FieldOptions to override the default value for the FILENAME field.
            Document        doc     = new Document(MyDir + "Document.docx");
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.MoveToDocumentEnd();
            builder.Writeln();

            // This FILENAME field will display the file name of the document we opened
            FieldFileName field = (FieldFileName)builder.InsertField(FieldType.FieldFileName, true);

            field.Update();

            Assert.AreEqual(" FILENAME ", field.GetFieldCode());
            Assert.AreEqual("Document.docx", field.Result);

            builder.Writeln();

            // By default, the FILENAME field does not show the full path, and we can change this
            field = (FieldFileName)builder.InsertField(FieldType.FieldFileName, true);
            field.IncludeFullPath = true;

            // We can override the values displayed by our FILENAME fields by setting this attribute
            doc.FieldOptions.FileName = "FieldOptions.FILENAME.docx";
            field.Update();

            Assert.AreEqual(" FILENAME  \\p", field.GetFieldCode());
            Assert.AreEqual("FieldOptions.FILENAME.docx", field.Result);

            doc.UpdateFields();
            doc.Save(ArtifactsDir + doc.FieldOptions.FileName);
            //ExEnd

            doc = new Document(ArtifactsDir + "FieldOptions.FILENAME.docx");

            Assert.IsNull(doc.FieldOptions.FileName);
            TestUtil.VerifyField(FieldType.FieldFileName, " FILENAME ", "FieldOptions.FILENAME.docx", doc.Range.Fields[0]);
        }