How to read .docx file in C# as a string

  public string ConvertDocxFileInToString(string path)
        { 
            var builder = new StringBuilder();
            using (var doc = WordprocessingDocument.Open(path, false))
            {
                foreach (var el in doc.MainDocumentPart.Document.Body.Descendants<Text>())
                {
                    builder.AppendLine(el.InnerText);
                }
            }
            return builder.ToString();
        }

Leave a Reply

Your email address will not be published. Required fields are marked *