2

I want to add a new item to a sharepoint list using /_vti_bin/Lists.asmx web service.

I have used the following code

        SharePointListService.Lists currentListService = new SharePointListService.Lists();
        currentListService.Credentials = new System.Net.NetworkCredential("UserName", "Password");
        XmlDocument doc = new XmlDocument();
        XmlElement batch_element = doc.CreateElement("Batch");
        string item = "<Method ID=\"1\" Cmd=\"New\">" + "<Field Name=\"ID\">New</Field>" + "<Field Name=\"Title\">This is a test</Field>" + "</Method>";
        batch_element.InnerXml = item;
        currentListService.UpdateListItems("Resources", batch_element);

This is giving me an Access Denied Error. Am I doing something wrong in code or is there any other work around to add list item to Sharepoint Online list using /_vti_bin/Lists.asmx webservice.

2 Answers 2

3

Finally I got my issue resolved. We can directly authenticate Sharepoint Online site by using the below code

using (ClientContext clientContext = new ClientContext(siteURL))
{
    SecureString passWord = new SecureString();
    foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
    clientContext.Credentials = new SharePointOnlineCredentials(siteUserName, passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
}

Here we can use client side object model to authenticate the Sharepoint online site.

Read more about it here:

Authenticating .NET Client Object Model

1

I don't think you can authorize towards #sharepoint-online via NetworkCredentials - try using claims instead:

How to do active authentication to Office 365 and SharePoint Online

1
  • Thanks Dag, I have worked out the problem using client side object model.
    – Sushri
    Commented Dec 4, 2013 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.