diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property.sln b/Word-document/Copy-document-property/.NET/Copy-document-property.sln new file mode 100644 index 000000000..f779eb361 --- /dev/null +++ b/Word-document/Copy-document-property/.NET/Copy-document-property.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Copy-document-property", "Copy-document-property\Copy-document-property.csproj", "{DB7EB08A-7BE8-46B4-9F2E-883902C8E157}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DB7EB08A-7BE8-46B4-9F2E-883902C8E157}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB7EB08A-7BE8-46B4-9F2E-883902C8E157}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB7EB08A-7BE8-46B4-9F2E-883902C8E157}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB7EB08A-7BE8-46B4-9F2E-883902C8E157}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7B24782A-F2D6-4C1A-ACF6-46D747189EE8} + EndGlobalSection +EndGlobal diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property/Copy-document-property.csproj b/Word-document/Copy-document-property/.NET/Copy-document-property/Copy-document-property.csproj new file mode 100644 index 000000000..26af757f6 --- /dev/null +++ b/Word-document/Copy-document-property/.NET/Copy-document-property/Copy-document-property.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + Copy_document_property + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property/Data/SourceDocument.docx b/Word-document/Copy-document-property/.NET/Copy-document-property/Data/SourceDocument.docx new file mode 100644 index 000000000..6779070b9 Binary files /dev/null and b/Word-document/Copy-document-property/.NET/Copy-document-property/Data/SourceDocument.docx differ diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property/Data/TargetDocument.docx b/Word-document/Copy-document-property/.NET/Copy-document-property/Data/TargetDocument.docx new file mode 100644 index 000000000..19bc022ec Binary files /dev/null and b/Word-document/Copy-document-property/.NET/Copy-document-property/Data/TargetDocument.docx differ diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property/Output/.gitkeep b/Word-document/Copy-document-property/.NET/Copy-document-property/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Word-document/Copy-document-property/.NET/Copy-document-property/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Word-document/Copy-document-property/.NET/Copy-document-property/Program.cs b/Word-document/Copy-document-property/.NET/Copy-document-property/Program.cs new file mode 100644 index 000000000..b1c76e42e --- /dev/null +++ b/Word-document/Copy-document-property/.NET/Copy-document-property/Program.cs @@ -0,0 +1,88 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO; + +//Load an existing main Word document. +using (WordDocument targetDocument = new WordDocument(@"../../../Data/TargetDocument.docx", FormatType.Docx)) +{ + //Load an existing template Word document. + using (WordDocument sourceDocument = new WordDocument(@"../../../Data/SourceDocument.docx", FormatType.Docx)) + { + //Move Built-in document properties from one Word document to another Word document. + MoveBuiltinDocumentProperties(sourceDocument, targetDocument); + //Move custom document properties from one Word document to another Word document. + MoveCustomDocumentProperties(sourceDocument, targetDocument); + //Save the Word document. + targetDocument.Save(@"../../../Output/Result.docx"); + } +} + +/// +/// Move Built-in document properties from one Word document to another Word document. +/// +void MoveBuiltinDocumentProperties(WordDocument sourceDocument, WordDocument targetDocument) +{ + if (sourceDocument.BuiltinDocumentProperties.Author != null) + targetDocument.BuiltinDocumentProperties.Author = sourceDocument.BuiltinDocumentProperties.Author; + + if (sourceDocument.BuiltinDocumentProperties.Title != null) + targetDocument.BuiltinDocumentProperties.Title = sourceDocument.BuiltinDocumentProperties.Title; + + if (sourceDocument.BuiltinDocumentProperties.Subject != null) + targetDocument.BuiltinDocumentProperties.Subject = sourceDocument.BuiltinDocumentProperties.Subject; + + if (sourceDocument.BuiltinDocumentProperties.Keywords != null) + targetDocument.BuiltinDocumentProperties.Keywords = sourceDocument.BuiltinDocumentProperties.Keywords; + + if (sourceDocument.BuiltinDocumentProperties.Comments != null) + targetDocument.BuiltinDocumentProperties.Comments = sourceDocument.BuiltinDocumentProperties.Comments; + + if (sourceDocument.BuiltinDocumentProperties.Template != null) + targetDocument.BuiltinDocumentProperties.Template = sourceDocument.BuiltinDocumentProperties.Template; + + if (sourceDocument.BuiltinDocumentProperties.LastAuthor != null) + targetDocument.BuiltinDocumentProperties.LastAuthor = sourceDocument.BuiltinDocumentProperties.LastAuthor; + + if (sourceDocument.BuiltinDocumentProperties.Thumbnail != null) + targetDocument.BuiltinDocumentProperties.Thumbnail = sourceDocument.BuiltinDocumentProperties.Thumbnail; + + if (sourceDocument.BuiltinDocumentProperties.ApplicationName != null) + targetDocument.BuiltinDocumentProperties.ApplicationName = sourceDocument.BuiltinDocumentProperties.ApplicationName; + + if (sourceDocument.BuiltinDocumentProperties.Category != null) + targetDocument.BuiltinDocumentProperties.Category = sourceDocument.BuiltinDocumentProperties.Category; + + if (sourceDocument.BuiltinDocumentProperties.Company != null) + targetDocument.BuiltinDocumentProperties.Company = sourceDocument.BuiltinDocumentProperties.Company; + + if (sourceDocument.BuiltinDocumentProperties.Manager != null) + targetDocument.BuiltinDocumentProperties.Manager = sourceDocument.BuiltinDocumentProperties.Manager; + + if (sourceDocument.BuiltinDocumentProperties.RevisionNumber != null) + targetDocument.BuiltinDocumentProperties.RevisionNumber = sourceDocument.BuiltinDocumentProperties.RevisionNumber; + + if (sourceDocument.BuiltinDocumentProperties.CreateDate != null) + targetDocument.BuiltinDocumentProperties.CreateDate = sourceDocument.BuiltinDocumentProperties.CreateDate; + + if (sourceDocument.BuiltinDocumentProperties.DocSecurity != -2147483648) + targetDocument.BuiltinDocumentProperties.DocSecurity = sourceDocument.BuiltinDocumentProperties.DocSecurity; + + if (sourceDocument.BuiltinDocumentProperties.LastPrinted != null) + targetDocument.BuiltinDocumentProperties.LastPrinted = sourceDocument.BuiltinDocumentProperties.LastPrinted; + + if (sourceDocument.BuiltinDocumentProperties.LastSaveDate != null) + targetDocument.BuiltinDocumentProperties.LastSaveDate = sourceDocument.BuiltinDocumentProperties.LastSaveDate; + + if (sourceDocument.BuiltinDocumentProperties.TotalEditingTime != null) + targetDocument.BuiltinDocumentProperties.TotalEditingTime = sourceDocument.BuiltinDocumentProperties.TotalEditingTime; +} + +/// +/// Move custom document properties from one Word document to another Word document. +/// +void MoveCustomDocumentProperties(WordDocument sourceDocument, WordDocument targetDocument) +{ + for (int i = 0; i < sourceDocument.CustomDocumentProperties.Count; i++) + { + targetDocument.CustomDocumentProperties.Add(sourceDocument.CustomDocumentProperties[i].Name, sourceDocument.CustomDocumentProperties[i].Value); + } +} \ No newline at end of file