I have about 400 files in .docx format, and I need to determine the length of each in #pages.
So, I want to write C# code for selecting the folder that contains the
Modern solution (based on Jignesh Thakker's answer): Open XML SDK is no longer there, but it is published on Github and even support .NET Core. You do not need MS Office on the server/running machine.
Install the Nuget package:
Install-Package DocumentFormat.OpenXml
The code:
using DocumentFormat.OpenXml.Packaging;
private int CountWordPage(string filePath)
{
using (var wordDocument = WordprocessingDocument.Open(filePath, false))
{
return int.Parse(wordDocument.ExtendedFilePropertiesPart.Properties.Pages.Text);
}
}