Esempio n. 1
0
            void IDocumentPartSavingCallback.DocumentPartSaving(DocumentPartSavingArgs args)
            {
                Assert.True(args.Document.OriginalFileName.EndsWith("Rendering.docx"));

                string partType = "";

                switch (mDocumentSplitCriteria)
                {
                case DocumentSplitCriteria.PageBreak:
                    partType = "Page";
                    break;

                case DocumentSplitCriteria.ColumnBreak:
                    partType = "Column";
                    break;

                case DocumentSplitCriteria.SectionBreak:
                    partType = "Section";
                    break;

                case DocumentSplitCriteria.HeadingParagraph:
                    partType = "Paragraph from heading";
                    break;
                }

                string partFileName = $"{mOutFileName} part {++mCount}, of type {partType}{Path.GetExtension(args.DocumentPartFileName)}";

                // We can designate the filename and location of each output file either by filename
                args.DocumentPartFileName = partFileName;

                // Or we can make a new stream and choose the location of the file at construction
                args.DocumentPartStream = new FileStream(ArtifactsDir + partFileName, FileMode.Create);
                Assert.True(args.DocumentPartStream.CanWrite);
                Assert.False(args.KeepDocumentPartStreamOpen);
            }
            void IDocumentPartSavingCallback.DocumentPartSaving(DocumentPartSavingArgs args)
            {
                // We can access the entire source document via the "Document" property.
                Assert.True(args.Document.OriginalFileName.EndsWith("Rendering.docx"));

                string partType = string.Empty;

                switch (mDocumentSplitCriteria)
                {
                case DocumentSplitCriteria.PageBreak:
                    partType = "Page";
                    break;

                case DocumentSplitCriteria.ColumnBreak:
                    partType = "Column";
                    break;

                case DocumentSplitCriteria.SectionBreak:
                    partType = "Section";
                    break;

                case DocumentSplitCriteria.HeadingParagraph:
                    partType = "Paragraph from heading";
                    break;
                }

                string partFileName = $"{mOutFileName} part {++mCount}, of type {partType}{Path.GetExtension(args.DocumentPartFileName)}";

                // Below are two ways of specifying where Aspose.Words will save each part of the document.
                // 1 -  Set a filename for the output part file:
                args.DocumentPartFileName = partFileName;

                // 2 -  Create a custom stream for the output part file:
                args.DocumentPartStream = new FileStream(ArtifactsDir + partFileName, FileMode.Create);

                Assert.True(args.DocumentPartStream.CanWrite);
                Assert.False(args.KeepDocumentPartStreamOpen);
            }