diff --git a/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word.sln b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word.sln new file mode 100644 index 000000000..003ccc111 --- /dev/null +++ b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove-embedded-MP4-files-from-Word", "Remove-embedded-MP4-files-from-Word\Remove-embedded-MP4-files-from-Word.csproj", "{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Data/Template.docx b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Data/Template.docx new file mode 100644 index 000000000..af9dced64 Binary files /dev/null and b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Data/Template.docx differ diff --git a/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Output/.gitkeep b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Program.cs b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Program.cs new file mode 100644 index 000000000..0af298787 --- /dev/null +++ b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Program.cs @@ -0,0 +1,50 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + + +// Load the Word document from the specified path +using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx"))) +{ + // Find all OLE objects in the document where the ObjectType is "Package" (i.e., embedded file) + List oleObjects = document.FindAllItemsByProperty(EntityType.OleObject, "ObjectType", "Package"); + + if (oleObjects != null) + { + // Iterate through each OLE object found in the document + foreach (Entity entity in oleObjects) + { + // Cast the entity to a WOleObject + WOleObject oleObject = entity as WOleObject; + + // Get the native (embedded) data from the OLE object + byte[] nativeData = oleObject.NativeData; + + // Check if the embedded file is a .mp4 video + if (oleObject.PackageFileName.EndsWith(".mp4")) + { + // Get the paragraph that owns the OLE object + WParagraph ownerPara = oleObject.OwnerParagraph; + + // Loop to remove all related field code entities until the FieldEnd is reached + while (true) + { + // Get the next sibling entity in the paragraph + Entity nextEntity = entity.NextSibling as Entity; + + // Remove the sibling entity from the paragraph + ownerPara.ChildEntities.Remove(nextEntity); + + // Stop when the field end marker is reached + if ((nextEntity is WFieldMark) && (nextEntity as WFieldMark).Type == FieldMarkType.FieldEnd) + break; + } + + // Finally, remove the OLE object itself from the paragraph + ownerPara.ChildEntities.Remove(entity); + } + } + } + + // Save the modified Word document to the output path + document.Save(Path.GetFullPath(@"Output/Result.docx"), FormatType.Docx); +} diff --git a/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Remove-embedded-MP4-files-from-Word.csproj b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Remove-embedded-MP4-files-from-Word.csproj new file mode 100644 index 000000000..bb2d49492 --- /dev/null +++ b/Paragraphs/Remove-embedded-MP4-files-from-Word/.NET/Remove-embedded-MP4-files-from-Word/Remove-embedded-MP4-files-from-Word.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Remove_embedded_MP4_files_from_Word + enable + enable + + + + + + + + + Always + + + Always + + + +