File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <Solution >
2+ <Project Path =" Extract-bookmark-content-as-HTML/Extract-bookmark-content-as-HTML.csproj" />
3+ </Solution >
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net8.0</TargetFramework >
6+ <RootNamespace >Extract_bookmark_content_as_HTML</RootNamespace >
7+ <ImplicitUsings >enable</ImplicitUsings >
8+ <Nullable >enable</Nullable >
9+ </PropertyGroup >
10+
11+ <ItemGroup >
12+ <PackageReference Include =" Syncfusion.DocIO.Net.Core" Version =" *" />
13+ </ItemGroup >
14+
15+ <ItemGroup >
16+ <Compile Update =" Program.cs" >
17+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
18+ </Compile >
19+ </ItemGroup >
20+
21+ <ItemGroup >
22+ <None Update =" Data\Input.docx" >
23+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
24+ </None >
25+ <None Update =" Output\.gitkeep" >
26+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
27+ </None >
28+ </ItemGroup >
29+
30+ </Project >
Original file line number Diff line number Diff line change 1+
Original file line number Diff line number Diff line change 1+ using Syncfusion . DocIO ;
2+ using Syncfusion . DocIO . DLS ;
3+
4+ namespace Extract_bookmark_Content
5+ {
6+ class Program
7+ {
8+ static void Main ( string [ ] args )
9+ {
10+ // Create an input file stream to open the document
11+ using ( FileStream inputStream = new FileStream ( Path . GetFullPath ( @"Data/Input.docx" ) , FileMode . Open , FileAccess . Read ) )
12+ {
13+ //Creates a new Word document.
14+ using ( WordDocument document = new WordDocument ( inputStream , FormatType . Docx ) )
15+ {
16+ // Create the bookmark navigator instance
17+ BookmarksNavigator bookmarkNavigator = new BookmarksNavigator ( document ) ;
18+ // Move to the bookmark
19+ bookmarkNavigator . MoveToBookmark ( "Adventure_Bkmk" ) ;
20+ // Get the bookmark content as a new Word document part.
21+ WordDocumentPart bookmarkPart = bookmarkNavigator . GetContent ( ) ;
22+ // Load the extracted content into a temporary Word document for modification or export.
23+ using ( WordDocument tempDoc = bookmarkPart . GetAsWordDocument ( ) )
24+ {
25+ //Creates file stream.
26+ using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Result.html" ) , FileMode . Create , FileAccess . ReadWrite ) )
27+ {
28+ //Saves the Word document to file stream.
29+ tempDoc . Save ( outputFileStream , FormatType . Html ) ;
30+ }
31+ }
32+ }
33+ }
34+ }
35+ }
36+ }
37+
You can’t perform that action at this time.
0 commit comments