Skip to content

ES-958622 - Add GitHub samples for APIs to set editable ranges in protected DOCX documents #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-editable-range-in-a-table", "Add-editable-range-in-a-table\Add-editable-range-in-a-table.csproj", "{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DF5F92E-BE60-4875-A5F7-1363B43AF83A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1FBCA517-BE3F-40EF-B53A-536B02603ECA}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_editable_range_in_a_table</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using System.IO;

namespace Add_editable_range_in_a_table
{
class Program
{
static void Main(string[] args)
{
// Load the Word document
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx")))
{
// Access the first table in the first section of the document
WTable table = document.Sections[0].Tables[0] as WTable;
// Access the paragraph in the third row and third column of the table
WParagraph paragraph = table[2, 2].ChildEntities[0] as WParagraph;
// Create a new editable range start for the table cell paragraph
EditableRangeStart editableRangeStart = new EditableRangeStart(document);
// Insert the editable range start at the beginning of the paragraph
paragraph.ChildEntities.Insert(0, editableRangeStart);
// Set the editor group for the editable range to allow everyone to edit
editableRangeStart.EditorGroup = EditorType.Everyone;
// Apply editable range to second column only
editableRangeStart.FirstColumn = 1;
editableRangeStart.LastColumn = 1;
// Access the paragraph
paragraph = table[5, 2].ChildEntities[0] as WParagraph;
// Append an editable range end to close the editable region
paragraph.AppendEditableRangeEnd();
//Sets the protection with password and allows only reading
document.Protect(ProtectionType.AllowOnlyReading, "password");
//Creates file stream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream
document.Save(outputStream, FormatType.Docx);
}
}
}
}
}
25 changes: 25 additions & 0 deletions Security/Add-editable-range/.NET/Add-editable-range.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-editable-range", "Add-editable-range\Add-editable-range.csproj", "{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B875FB3-1D7A-4C86-A1E7-BA77906674BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {74BE8749-A1F1-427A-92CF-977EEAC2B413}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_editable_range</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

38 changes: 38 additions & 0 deletions Security/Add-editable-range/.NET/Add-editable-range/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;

namespace Add_editable_range
{
class Program
{
static void Main(string[] args)
{
//Create a Word document
using (WordDocument document = new WordDocument())
{
//Add a section and a paragraph to the Word document
document.EnsureMinimal();
WParagraph paragraph = document.LastParagraph;

//Append text to the paragraph
paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ");

//Add an editable range to the paragraph
EditableRangeStart editableRangeStart = paragraph.AppendEditableRangeStart();
paragraph.AppendText("sample databases are based, is a large, multinational manufacturing company.");
paragraph.AppendEditableRangeEnd(editableRangeStart);

//Set protection with a password to allow read-only access
document.Protect(ProtectionType.AllowOnlyReading, "password");

//Creates file stream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream
document.Save(outputStream, FormatType.Docx);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-editable-range-by-id", "Find-editable-range-by-id\Find-editable-range-by-id.csproj", "{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{003864C5-ADA1-42E9-99FA-B4AC912ACC0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EAADC1D0-BF63-4DF6-B606-1CECD2395ADA}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Find_editable_range_by_id</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using System.IO;

namespace Find_editable_range_by_id
{
class Program
{
static void Main(string[] args)
{
//Loads an existing Word document
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Get the editable range by Id
EditableRange editableRange = document.EditableRanges.FindById("0");

//Creates file stream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream
document.Save(outputStream, FormatType.Docx);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Group-permission-for-editable-range", "Group-permission-for-editable-range\Group-permission-for-editable-range.csproj", "{5F708087-D10D-4049-8061-7AC48B9F5B34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F708087-D10D-4049-8061-7AC48B9F5B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F708087-D10D-4049-8061-7AC48B9F5B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F708087-D10D-4049-8061-7AC48B9F5B34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F708087-D10D-4049-8061-7AC48B9F5B34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC12DB2A-6A3E-49E5-AB92-9DA3A009B08C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Group_permission_for_editable_range</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using System.IO;

namespace Group_permission_for_editable_range
{
class Program
{
static void Main(string[] args)
{
//Creates a Word document
using (WordDocument document = new WordDocument())
{
//Adds a section and a paragraph in the Word document
document.EnsureMinimal();
WParagraph paragraph = document.LastParagraph;

//Append text into the paragraph
paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ");

//Adds an editable range to the paragraph
EditableRangeStart editableRangeStart = paragraph.AppendEditableRangeStart();

//Set the editor group
editableRangeStart.EditableRange.EditorGroup = EditorType.Everyone;

paragraph.AppendText("sample databases are based, is a large, multinational manufacturing company.");
paragraph.AppendEditableRangeEnd(editableRangeStart);

//Sets the protection with password and allows only reading
document.Protect(ProtectionType.AllowOnlyReading, "password");

//Creates file stream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream
document.Save(outputStream, FormatType.Docx);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove-editable-range-at-an-index", "Remove-editable-range-at-an-index\Remove-editable-range-at-an-index.csproj", "{C8E35D6C-57E9-45A1-A259-3BC308B29EBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C8E35D6C-57E9-45A1-A259-3BC308B29EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8E35D6C-57E9-45A1-A259-3BC308B29EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8E35D6C-57E9-45A1-A259-3BC308B29EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8E35D6C-57E9-45A1-A259-3BC308B29EBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C0428B68-C8C4-43EB-9E32-15B96448C95E}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading