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();
getlists();
// 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)
{
securePassword.AppendChar(c);
}
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));
context.ExecuteQuery();
results.ToList().ForEach(x =>
{
Console.WriteLine("List: " + x.Title);
});
context.Dispose();
}
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'>
<Default>IT</Default>
<CHOICES>
<CHOICE>IT</CHOICE>
<CHOICE>Sales</CHOICE>
<CHOICE>Research and Development</CHOICE>
<CHOICE>CSR</CHOICE>
</CHOICES>
</Field>
", 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.Update();
listItem = list.AddItem(itemCreationInfo);
listItem["Title"] = "New Incident Management System";
listItem["Category"] = "IT";
listItem.Update();
listItem = list.AddItem(itemCreationInfo);
listItem["Title"] = "New internal sales strategy";
listItem["Category"] = "Sales";
listItem.Update();
listItem = list.AddItem(itemCreationInfo);
listItem["Title"] = "Youtube product visibility";
listItem["Category"] = "CSR";
listItem.Update();
clientContext.ExecuteQuery();
}
}