From 4e4eb9403540f069996685d134270e8c62790f2c Mon Sep 17 00:00:00 2001 From: GOPINATHSF4767 Date: Fri, 13 Feb 2026 13:23:49 +0530 Subject: [PATCH 1/2] Modified sample --- .../Clone-and-merge-word-document.csproj | 12 +++- .../Output/.gitkeep | 1 + .../Clone-and-merge-word-document/Program.cs | 61 +++++-------------- 3 files changed, 26 insertions(+), 48 deletions(-) create mode 100644 Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Output/.gitkeep diff --git a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Clone-and-merge-word-document.csproj b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Clone-and-merge-word-document.csproj index ad8c6950f..bb91546fb 100644 --- a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Clone-and-merge-word-document.csproj +++ b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Clone-and-merge-word-document.csproj @@ -11,5 +11,15 @@ - + + + Always + + + Always + + + Always + + diff --git a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Output/.gitkeep b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs index 1a814477c..fbd724e5c 100644 --- a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs +++ b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -using System.Diagnostics; +using System.Diagnostics; using Syncfusion.DocIO; using Syncfusion.DocIO.DLS; @@ -7,55 +6,23 @@ class Program { static void Main() { - string sourceFolder = Path.GetFullPath("../../../Data/SourceDocument/"); - string destinationFolder = Path.GetFullPath("../../../Data/DestinationDocument/"); - string outputFolder = Path.GetFullPath("../../../Output/"); - - Directory.CreateDirectory(outputFolder); - - // Get all source files - string[] sourceFiles = Directory.GetFiles(sourceFolder, "*.docx"); - - foreach (string sourcePath in sourceFiles) + using (FileStream sourceFileStream = new FileStream(Path.GetFullPath(@"Data/SourceDocument/Document-100.docx"), FileMode.Open, FileAccess.Read)) { - string fileName = Path.GetFileName(sourcePath); - string destinationPath = Path.Combine(destinationFolder, fileName); - - if (!File.Exists(destinationPath)) - { - Console.WriteLine($"Skipping {fileName} - No matching destination file found."); - continue; - } - - string outputPath = Path.Combine(outputFolder, fileName); - - Stopwatch stopwatch = Stopwatch.StartNew(); - - try + using (FileStream destinationFileStream = new FileStream(Path.GetFullPath(@"Data/DestinationDocument/Document-100.docx"), FileMode.Open, FileAccess.Read)) { - // Open source and destination document - WordDocument sourceDocument = new WordDocument(sourcePath); - WordDocument destinationDocument = new WordDocument(destinationPath); - - // Clone and merge all slides - foreach (WSection section in sourceDocument.Sections) + WordDocument mainDoc = new WordDocument(sourceFileStream, FormatType.Docx); + WordDocument mergeDoc = new WordDocument(destinationFileStream, FormatType.Docx); + Stopwatch sw = Stopwatch.StartNew(); + mainDoc.ImportContent(mergeDoc, ImportOptions.UseDestinationStyles); + sw.Stop(); + Console.WriteLine("Time taken for Merge Documents:" + sw.Elapsed.TotalSeconds); + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MergedDocument.docx"), FileMode.Create)) { - WSection clonedSection = section.Clone(); - destinationDocument.Sections.Add(clonedSection); + mainDoc.Save(outputFileStream, FormatType.Docx); } - - // Save the merged document. - destinationDocument.Save(outputPath); - - stopwatch.Stop(); - Console.WriteLine($"{fileName} is cloned and merged in {stopwatch.Elapsed.TotalSeconds} seconds."); - sourceDocument.Close(); - destinationDocument.Close(); - } - catch (Exception ex) - { - Console.WriteLine($"Error processing {fileName}: {ex.Message}"); + mainDoc.Close(); + mergeDoc.Close(); } } } -} +} \ No newline at end of file From bae990e71af90b43e54d761871b16ca72a037653 Mon Sep 17 00:00:00 2001 From: GOPINATHSF4767 Date: Fri, 13 Feb 2026 17:19:51 +0530 Subject: [PATCH 2/2] Modified sample --- .../Clone-and-merge-word-document/Program.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs index fbd724e5c..fa1f34447 100644 --- a/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs +++ b/Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Program.cs @@ -10,18 +10,20 @@ static void Main() { using (FileStream destinationFileStream = new FileStream(Path.GetFullPath(@"Data/DestinationDocument/Document-100.docx"), FileMode.Open, FileAccess.Read)) { - WordDocument mainDoc = new WordDocument(sourceFileStream, FormatType.Docx); - WordDocument mergeDoc = new WordDocument(destinationFileStream, FormatType.Docx); - Stopwatch sw = Stopwatch.StartNew(); - mainDoc.ImportContent(mergeDoc, ImportOptions.UseDestinationStyles); - sw.Stop(); - Console.WriteLine("Time taken for Merge Documents:" + sw.Elapsed.TotalSeconds); - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MergedDocument.docx"), FileMode.Create)) + using (WordDocument mainDoc = new WordDocument(sourceFileStream, FormatType.Docx)) { - mainDoc.Save(outputFileStream, FormatType.Docx); - } - mainDoc.Close(); - mergeDoc.Close(); + using (WordDocument mergeDoc = new WordDocument(destinationFileStream, FormatType.Docx)) + { + Stopwatch sw = Stopwatch.StartNew(); + mainDoc.ImportContent(mergeDoc, ImportOptions.UseDestinationStyles); + sw.Stop(); + Console.WriteLine("Time taken for Merge Documents:" + sw.Elapsed.TotalSeconds); + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MergedDocument.docx"), FileMode.Create)) + { + mainDoc.Save(outputFileStream, FormatType.Docx); + } + } + } } } }