diff --git a/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph.sln b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph.sln new file mode 100644 index 000000000..e8c888b6b --- /dev/null +++ b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36518.9 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-Editable-range-to-specific-paragraph", "Add-Editable-range-to-specific-paragraph\Add-Editable-range-to-specific-paragraph.csproj", "{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {48134F0E-F228-4631-90C5-02A0A3A5DD6B} + EndGlobalSection +EndGlobal diff --git a/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Add-Editable-range-to-specific-paragraph.csproj b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Add-Editable-range-to-specific-paragraph.csproj new file mode 100644 index 000000000..2e40fd88f --- /dev/null +++ b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Add-Editable-range-to-specific-paragraph.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Add_Editable_range_to_specific_paragraph + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Data/Template.docx b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Data/Template.docx new file mode 100644 index 000000000..5ca5696d3 Binary files /dev/null and b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Data/Template.docx differ diff --git a/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Output/.gitkeep b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Program.cs b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Program.cs new file mode 100644 index 000000000..5c3bd9519 --- /dev/null +++ b/Security/Add-Editable-range-to-specific-paragraph/.NET/Add-Editable-range-to-specific-paragraph/Program.cs @@ -0,0 +1,45 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO; + +namespace Add_Editable_range_to_specific_paragraph +{ + class Program + { + static void Main(string[] args) + { + // Load the Word document + using (WordDocument document = new WordDocument(Path.GetFullPath("Data/Template.docx"))) + { + // Access the first section of the document + WSection section = document.Sections[0]; + // Insert an editable range at index 1 in the 2nd paragraph + AddEditableRange(document, section.Paragraphs[1], 1); + // Insert an editable range at index 2 in the 4th paragraph + AddEditableRange(document, section.Paragraphs[3], 1); + // Insert an editable range at index 4 in the 12th paragraph + AddEditableRange(document, section.Paragraphs[11], 4); + // Save the modified document to the new file + document.Save(Path.GetFullPath(@"../../../Output/Result.docx")); + } + } + /// + /// Inserts an editable range at a specific index within a paragraph. + /// + /// The Word document instance + /// The paragraph where the editable range will be inserted. + /// The index within the paragraph's child entities to insert the editable range. + private static void AddEditableRange(WordDocument document, WParagraph paragraph, int index) + { + // Create the start of the editable range + EditableRangeStart editableRangeStart = new EditableRangeStart(document); + // Insert the editable range start at the specified index in the paragraph + paragraph.ChildEntities.Insert(index, editableRangeStart); + // Set the editor group to allow everyone to edit this range + editableRangeStart.EditorGroup = EditorType.Everyone; + // Create the end of the editable range + EditableRangeEnd editableRangeEnd = new EditableRangeEnd(document); + // Insert the editable range end after the editable content + paragraph.ChildEntities.Insert(index + 2, editableRangeEnd); + } + } +} diff --git a/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable.sln b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable.sln new file mode 100644 index 000000000..c1d50e404 --- /dev/null +++ b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36518.9 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-Text-and-Make-it-Editable", "Find-Text-and-Make-it-Editable\Find-Text-and-Make-it-Editable.csproj", "{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CDAFC3B6-0F05-4FBC-8B77-214AF0CA9392} + EndGlobalSection +EndGlobal diff --git a/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Data/Template.docx b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Data/Template.docx new file mode 100644 index 000000000..7032cbec1 Binary files /dev/null and b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Data/Template.docx differ diff --git a/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Find-Text-and-Make-it-Editable.csproj b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Find-Text-and-Make-it-Editable.csproj new file mode 100644 index 000000000..ba0e347a9 --- /dev/null +++ b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Find-Text-and-Make-it-Editable.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Find_Text_and_Make_it_Editable + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Output/.gitkeep b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Program.cs b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Program.cs new file mode 100644 index 000000000..d72fe1b1d --- /dev/null +++ b/Security/Find-Text-and-Make-it-Editable/.NET/Find-Text-and-Make-it-Editable/Program.cs @@ -0,0 +1,50 @@ +using Syncfusion.DocIO.DLS; + +namespace Find_Text_and_Make_it_Editable +{ + public class Program + { + public static void Main(string[] args) + { + //Loads template document + WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx")); + // Find all instances of the target text (text, case-insensitive, whole word match) + TextSelection[] textSelections = document.FindAll("Adventure Works Cycles", false, true); + + // Append editable ranges around each matched text. + foreach (var selection in textSelections) + { + AppendEditableRange(selection); + } + // save and close the document + document.Save(Path.GetFullPath(Path.GetFullPath(@"../../../Output/Result.docx"))); + document.Close(); + } + + public static void AppendEditableRange(TextSelection selection) + { + // Get the text range from the selection. + WTextRange[] textRanges = selection.GetRanges(); + if (textRanges.Length > 0) + { + // Get the first and last text ranges in the selection. + WTextRange startTextRange = textRanges[0]; + WTextRange endTextRange = textRanges[textRanges.Length - 1]; + // Get the paragraph that owns the start text range. + WParagraph paragraph = startTextRange.OwnerParagraph; + // Create a new EditableRangeStart and assign it to everyone by default. + EditableRangeStart editableRangeStart = new EditableRangeStart(paragraph.Document); + editableRangeStart.EditorGroup = EditorType.Everyone; + // Find the index of the start text range within the paragraph's child entities. + int startTextRangeIndex = paragraph.ChildEntities.IndexOf(startTextRange); + // Insert the editable range start before the start text range. + paragraph.ChildEntities.Insert(startTextRangeIndex, editableRangeStart); + // Create a new EditableRangeEnd linked to the start. + EditableRangeEnd editableRangeEnd = new EditableRangeEnd(paragraph.Document, editableRangeStart); + // Find the index of the end text range and insert the editable range end after it. + int endTextRangeIndex = paragraph.ChildEntities.IndexOf(endTextRange); + paragraph.ChildEntities.Insert(endTextRangeIndex + 1, editableRangeEnd); + } + } + } +}