如何使用C#控制檯應用程序訪問SharePoint庫路徑中的文檔。使用Azure AD進行內部認證配置SharePoint以進行遠程訪問。Sharepoint Azure AD身份驗證
配置之前,C#控制檯應用程序可以使用SharePoint Client Object Model(CSOM)訪問SharePoint庫路徑中的文檔。
下面是示例代碼:
ClientContext context = new ClientContext(RootLibraryPath);
SecureString passWord = new SecureString();
foreach (char c in Password.ToCharArray()) passWord.AppendChar(c);
context.Credentials = new NetworkCredential(UserName, passWord);
context.ExecuteQuery();
Web web = context.Web;
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope='RecursiveAll'>" +
"<Query>" +
"</Query>" +
"</View>";
List list = web.Lists.GetByTitle(libraryName);
ListItemCollection items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();