How do I program a C# program to read a Word file on the company's SharePoint

William Thompson 120 Reputation points
2024-07-25T16:00:24.4+00:00

There are several issues I am facing.

  1. A document in Microsoft Word format is difficult to open and parse through for reading from a C# program. Are their API's to do this from code?
  2. The document is on SharePoint. Does this mean I will need the ClientContext class and set up a username and password with a SecureString class?
  3. I would like to open the file and parse through it. HTML files are ASCII and easier to parse through. But saving a Word document as an HTML web page in SharePoint takes a simple text and adds CSS and Javascript content. It makes it look fancy for the end-user. Plus it makes it uneditable to another user. I want the end user to be able to edit the document. So we are stuck with having it as a Word document.
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,685 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 20,126 Reputation points Microsoft Vendor
    2024-07-26T06:10:43.1633333+00:00

    @William Thompson,

    To read a Word file on the company's SharePoint using a C# program, you can use the SharePoint Client Side Object Model (CSOM) and the Open XML SDK. The CSOM can be used to access SharePoint using the ClientContext class and set up a username and password with a SecureString class and the Open XML SDK can be used to read and manipulate the contents of the Word file.

    It is possible to save a Word document as an HTML web page in SharePoint, but this may not be the best option if you want the end user to be able to edit the document. Instead, you can use the CSOM to download the Word file and then use the Open XML SDK to read and manipulate the contents of the file.


    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.