Skip to content
Merged
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,3 @@
<Solution>
<Project Path="Extract-bookmark-content-as-HTML/Extract-bookmark-content-as-HTML.csproj" />
</Solution>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Extract_bookmark_content_as_HTML</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<Compile Update="Program.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Data\Input.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,37 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace Extract_bookmark_Content
{
class Program
{
static void Main(string[] args)
{
// Create an input file stream to open the document
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read))
{
//Creates a new Word document.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
// Create the bookmark navigator instance
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
// Move to the bookmark
bookmarkNavigator.MoveToBookmark("Adventure_Bkmk");
// Get the bookmark content as a new Word document part.
WordDocumentPart bookmarkPart = bookmarkNavigator.GetContent();
// Load the extracted content into a temporary Word document for modification or export.
using (WordDocument tempDoc = bookmarkPart.GetAsWordDocument())
{
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.html"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
tempDoc.Save(outputFileStream, FormatType.Html);
}
}
}
}
}
}
}

Loading