I succès connecter en ligneComment créer ClientContext en service Web .asmx
list.Credentials = new System.Net.NetworkCredential("domain\\username", "password");
mais ne peut pas se joindre à ClientContext
web service
: J'obtiens l'erreur 401. Comment ajouter nouvel élément à SPList sur SPSite à distance avec cette code? Qu'est-ce que j'ai besoin de réparer? Je vous remercie.
public void UpdateSPList(string Title)
{
using (AuthenticationSvc.Authentication authSvc = new AuthenticationSvc.Authentication())
{
try
{
using (ListsSvc.Lists list = new ListsSvc.Lists())
{
list.Url = @"http://example-site.com/_vti_bin/Lists.asmx";
list.CookieContainer = new System.Net.CookieContainer();
list.AllowAutoRedirect = true;
list.PreAuthenticate = true;
list.Credentials = new System.Net.NetworkCredential("domain\\username", "password");
string siteUrl = "http://example-site.com";
ClientContext context = new ClientContext(siteUrl);
List announcementsList = context.Web.Lists.GetByTitle("ListName");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = "New Item";
newItem.Update();
context.ExecuteQuery();
}
}
catch (Exception ex)
{
string errorEntry = ex.Message;
}
}
}