0

我尝试使用客户端代码 CSOM 从 SharePoint 上可用的讨论表单中获取讨论项目,我已成功连接但无法获取讨论...这是 sharePoint 的链接:-- https:///sites //GlobalDiscussion/SitePages/Community%20Home.aspx

下面是我的代码:------

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);
            }
        }
        
    }
}

如果有人可以帮助我,那就太好了...谢谢...

4

0 回答 0