I need to access a list in office 365 from a page in asp .net, this page is not in the office 365 server and I've tried various methods, for example via the web services in list.asmx but I got problems with the claim authentication, I have not found any practical example on how to do this. How can I insert an item in a list in office 365 from an asp .net site?

update - solution

you can find the solution in Accessing SharePoint Online from a Windows client but I would like to contribute with this code from http://sneakydev.blogspot.com.es/2013/05/using-c-csom-to-interact-with.html :

  Microsoft.SharePoint.Client.ClientContext context;
  context = GetContext();

// and in a class you put this

    // utility class for accessing office365
    private class Configuration
        public static string ServiceSiteUrl = "url";
        public static string ServiceUserName = "[email protected]";
        public static string ServicePassword = "password";

    static ClientContext GetContext()
        var securePassword = new SecureString();
        foreach (char c in Configuration.ServicePassword)

        var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);

        var context = new ClientContext(Configuration.ServiceSiteUrl);
        context.Credentials = onlineCredentials;

        return context;

    static void GetLists()
        var context = GetContext();
        var results = context.LoadQuery(context.Web.Lists.Include(list => list.Title, list => list.Id));
        results.ToList().ForEach(x =>
            Console.WriteLine("List: " + x.Title);


    static void CreateProjectList()
        ClientContext clientContext = GetContext();
        Web site = clientContext.Web;

        // Create the project list.
        ListCreationInformation listCreationInfo = new ListCreationInformation();
        listCreationInfo.Title = "Projects";
        listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
        List list = site.Lists.Add(listCreationInfo);

        // Add the category field to the list.
        Field catField = list.Fields.AddFieldAsXml(@"
            <Field Type='Choice' DisplayName='Category' Format='Dropdown'>
                  <CHOICE>Research and Development</CHOICE>
            ", true, AddFieldOptions.DefaultValue);

        // Add list data.
        ListItemCreationInformation itemCreationInfo = new ListItemCreationInformation();
        Microsoft.SharePoint.Client.ListItem listItem = list.AddItem(itemCreationInfo);
        listItem["Title"] = "New public facing website";
        listItem["Category"] = "IT";

        listItem = list.AddItem(itemCreationInfo);
        listItem["Title"] = "New Incident Management System";
        listItem["Category"] = "IT";

        listItem = list.AddItem(itemCreationInfo);
        listItem["Title"] = "New internal sales strategy";
        listItem["Category"] = "Sales";

        listItem = list.AddItem(itemCreationInfo);
        listItem["Title"] = "Youtube product visibility";
        listItem["Category"] = "CSR";


1 Answer 1


You can use Sharepoint client object model to access data from sharepoint:

SecureString password = new SecureString();

 foreach (char c in password)

            using (var context = new ClientContext(webUrl))
                context.Credentials = new SharePointOnlineCredentials(userName,password);
                List announcementsList = context.Web.Lists.GetByTitle("Announcements"); 

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); 
ListItem newItem = announcementsList.AddItem(itemCreateInfo); 
newItem["Title"] = "My New Item!"; 
newItem["Body"] = "Hello World!"; 


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.