Today, we will discuss how to disable the comments on Modern pages of Modern sites using CSOM. This article is basically targeted for beginners who are working on Modern Sites in Office 365.
Preparation
I am using the Visual Studio 2017 Community Edition which is freely available. Following are the common steps required to connect to a modern site and to access the page. Once preparation is done, we will do the actual code.
- Create the console application as shown below.
Figure 1: Office 365-SharePoint Online - Creating Console Application
- Add following keys to app.config files.
- <appSettings>
- <add key="CredentialsFilePath" value="C:\spo\knowledgejunction\knuser.txt" />
- </appSettings>
- Install the respective NuGet packages.
- Installing “SharePointOnline.CSOM” package for CSOM APIs to connect with our Office 365 site.
In Solution Explorer, right-click on references and click “Manage NuGet Packages” as shown below.
Figure 2: Office 365 - SharePoint Online - Manage NuGet Packages...
NuGet Package Manager will be opened. Under “Browse” tab, search for the key “Microsoft.SharePointOnline.CSOM”, and install the searched package as shown in the below figure.
Figure 3: Office 365 - SharePoint Online - Installing "Microsoft.SharePointOnline.CSOM" NuGet package
Once we have successfully installed the packages, references to the following assemblies will be added to our project.
Figure 4: Office 365 - SharePoint Online - Assemblies references added after installing "Microsoft.SharePointOnline.CSOM" NuGet package
- We will also need to install the package “sharepoint pnp coreonline” for accessing modern page so in NuGet Manager, search for the phrase.

Figure 5: Office 365 - SharePoint Online - Installing "SharePoint PnP Core Online" NuGet package
Once we have successfully installed the above NuGet package, the following assembly references are added to our package.
Figure 6: Office 365 - SharePoint Online - Assemblies references added after installing "SharePoint PnP Core Online" NuGet package
We could also see the progress of installing respective packages in the output window. Once we have the respective references in place, we can code.
- Installing “SharePointOnline.CSOM” package for CSOM APIs to connect with our Office 365 site.
Code
Following is the method to disable the page comments for given page in a given site.

Join the conversation! Your thoughts help the community grow.