Hello, I need your help.
I am using c# and open xml sdk 2.0 for accessing Word file.
For that, now i want to retrieve a chapter and paragraph based on the given text.
If the chapter contains my text then retrieve the paragraph containing that text...
FOR EXAMPLE: Given Word is: Chapter 1 - Events
Retrieve the chapter and paragraphs that containing the word "Chapter 1 - Events"
I want to search the given word on the Word file.
If any matches found, then i want to display that methods and insert into database according with this schema

code-behind (now the return on visual studio debug is list of chapters)
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string file = @"C:\Users\file.docx";
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(file, true))
{
Body body = wordDoc.MainDocumentPart.Document.Body;
string paras = "";
foreach (Paragraph p in wordDoc.MainDocumentPart.Document.Body.Descendants<Paragraph>().Where<Paragraph>(p => p.InnerText.Contains("Chapter")))
{
paras += p.InnerText + "<br/>";
}
Response.Write(paras);
}
}
}
}
file.docx
Chapter 1 - Events
- alert or disservices
Lorem ipsum dolor sit amet, consectetur adipiscing elit
….
….
- significant activities
Phasellus dui nunc, rutrum vitae dictum eleifend, ullamcorper hendrerit sem
….
….
Chapter 2 – Safety
- near miss
Praesent venenatis convallis nunc, quis ultrices massa
….
….
- security checks
Phasellus mollis dapibus porta. Phasellus ac tristique dui
….
….
Chapter 3 – Training
- environment
Nunc hendrerit scelerisque mauris vel eleifend
….
….
- upkeep
Mauris id elit nec nisl laoreet posuere. Donec ac molestie sem
….
….
database table
DROP TABLE IF EXISTS `chapters`;
CREATE TABLE `chapters` (
`chapter` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`subheading` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`contents` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;