getting 403 forrbidden when using caml to get a list
-
17-12-2020 - |
Вопрос
I just recently started to invest some time into CAML. I am trying to learn it. I think I have it down, but when I try executing the query I get a 403 forbidden. Anyone know a way to fix this. error comes a line 21
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace SharepointConnection
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://fufu.sharepoint.com/fpattegrosso";
ClientContext clientContext = new ClientContext(siteUrl);
Console.WriteLine("connected");
Console.ReadLine();
SP.List oList = clientContext.Web.Lists.GetByTitle("Log");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/><Value Type='Number'>0</value></Greq></Where></Query><RowLimiti>100</RowLimit></View>";
//Entry
ListItemCollection collListItem = oList.GetItems(query);
clientContext.Load(collListItem);
clientContext.ExecuteQuery(); // line 21
foreach(ListItem item in collListItem)
{
Console.WriteLine($"{item["Title"]}");
}
Console.Read();
}
}
}
Решение 2
follow this method in order to properly authenticate yourself to the sharepoint client.
Другие советы
It seems to be related to permission, therefore, initially would indicate that you will likely need to include your credentials with the client context, as the user will need access to the respective list.
using System;
using System.Net;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace SharepointConnection
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://fufu.sharepoint.com/fpattegrosso";
ClientContext clientContext = new ClientContext(siteUrl);
// Added Using System.Net ^^ ///////
NetworkCredential cred = new System.Net.NetworkCredential("username", "password", "domain");
clientContext.Credentials = cred;
Console.WriteLine("connected");
Console.ReadLine();
SP.List oList = clientContext.Web.Lists.GetByTitle("Log");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/><Value Type='Number'>0</value></Greq></Where></Query><RowLimiti>100</RowLimit></View>";
//Entry
ListItemCollection collListItem = oList.GetItems(query);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach(ListItem item in collListItem)
{
Console.WriteLine($"{item["Title"]}");
}
Console.Read();
}
}
}
Не связан с sharepoint.stackexchange