Skip to content

Commit 03306c9

Browse files
Removed the unaddressed samples added existing sample
1 parent a6e1666 commit 03306c9

File tree

1 file changed

+27
-37
lines changed
  • Word-document/Merge–multiple-Word-files-in-same-page/.NET/Merge–multiple-Word-files-in-same-page

1 file changed

+27
-37
lines changed
Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,46 @@
1-
using Syncfusion.DocIO;
1+
using Syncfusion.DocIO;
22
using Syncfusion.DocIO.DLS;
3+
using System.Runtime.Serialization;
34

4-
//Register Syncfusion license
5-
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc=");
6-
7-
//Get the list of source documents to be imported.
8-
List<string> sourceFileNames = new List<string>();
9-
sourceFileNames.Add("Data/Addressblock.docx");
10-
sourceFileNames.Add("Data/Salutation.docx");
5+
//Get the list of source document to be imported
6+
List<string> sourceFileNames = new List<string>();
7+
sourceFileNames.Add("Data/Addressblock.docx");
8+
sourceFileNames.Add("Data/Salutation.docx");
119
sourceFileNames.Add("Data/Greetings.docx");
1210

13-
//Get the full path of the destination document.
1411
string destinationFileName = Path.GetFullPath(@"Data/Title.docx");
15-
//Open a file stream to the destination document.
16-
using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
12+
using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1713
{
18-
//Opens the destination document.
19-
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
14+
//Opens the destination document
15+
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
2016
{
21-
//Calls the method to import other documents into the destination document.
22-
ImportOtherDocuments(sourceFileNames, destinationDocument);
23-
//Saves and closes the destination document.
24-
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.Write))
17+
ImportOtherDocuments(sourceFileNames, destinationDocument);
18+
//Saves and closes the destination document
19+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.Write))
2520
{
26-
destinationDocument.Save(outputStream, FormatType.Docx);
27-
//Closes the destination document.
28-
destinationDocument.Close();
21+
destinationDocument.Save(outputStream, FormatType.Docx);
22+
destinationDocument.Close();
2923
}
3024
}
3125
}
3226

33-
/// <summary>
34-
/// Import content from multiple source Word documents into a destination document.
35-
/// </summary>
36-
void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument) //Method to import content from source documents into the destination document
27+
void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument)
3728
{
38-
//Iterate through each source document from the list.
39-
foreach (string sourceFileName in sourceFiles)
29+
//Iterate through each source document from the list
30+
foreach (string sourceFileName in sourceFiles)
4031
{
41-
//Open the source document.
42-
using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
32+
//Open source document
33+
using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
4334
{
44-
//Opens the Word document from the file stream.
45-
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic)) //Initialize a WordDocument object for the source document
35+
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
4636
{
47-
//Set the break-code of the first section of the source document as NoBreak to avoid starting content on a new page.
48-
document.LastSection.BreakCode = SectionBreakCode.NoBreak;
49-
//Imports the content of the source document at the end of the destination document.
50-
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
51-
//Close the source document
52-
document.Close();
37+
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
38+
document.LastSection.BreakCode = SectionBreakCode.NoBreak;
39+
//Imports the contents of source document at the end of destination document
40+
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
41+
//Close the document.
42+
document.Close();
5343
}
5444
}
5545
}
56-
}
46+
}

0 commit comments

Comments
 (0)