0

I tried to fetch the discussion items from the discussion form available on the SharePoint using client side code CSOM and I am connected successfully but unable to fetch the discussions... Here is the link of the sharePoint :-- https:///sites//GlobalDiscussion/SitePages/Community%20Home.aspx

Below is my code :------

using System.Security;
using Microsoft.SharePoint.Client;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using MongoDB.Driver;
using MongoDB.Bson;
using Microsoft.SharePoint;

namespace ConnectToSPO
{
    class Program
    {
        static void Main(string[] args)
        {

           

            string webSPOUrl = "";
            string userName = "";
            
     
            SecureString password = new NetworkCredential("", "").SecurePassword;


            try
            {
                using (var context = new ClientContext(webSPOUrl))
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

                    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;

                    context.Credentials = new SharePointOnlineCredentials(userName, password);
                    Web web = context.Web;
                    context.ExecuteQuery();
                    

                    Console.WriteLine(web.ServerRelativeUrl);

                    var filePath = web.ServerRelativeUrl + "/GlobalDiscussion/SitePages/Community%20Home.aspx";
                    Console.WriteLine(filePath);
                    FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, filePath);

                    using (System.IO.StreamReader sr = new System.IO.StreamReader(fileInformation.Stream))
                    {
                        String line = sr.ReadToEnd();
                        Console.WriteLine(line);
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error is: " + ex.Message);
            }
        }
        
    }
}

It will be great if anyone can help me out ... Thank you...

Milad Dastan Zand
  • 1,062
  • 1
  • 10
  • 21
  • And what is the error you've got? – AndrewSilver Oct 27 '21 at 06:28
  • actually i am getting the content of the aspx page but i want directly the discussion topics ..i also tried to download the Community%20Home.aspx page from the share point so that i can remotely access the discussions but still the aspx page contain only backgound code and not the discussions and replies – shahbaz zeb Oct 27 '21 at 08:16
  • <%@ Assembly Name="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%> <%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WikiEditPage" :---------------------------------------code is like the above and not the actual discussions or replies – shahbaz zeb Oct 27 '21 at 08:17

0 Answers0