protected void GetListItem()
{
try
{
SecureString Password = new SecureString();
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
foreach (char c in "password")
{
Password.AppendChar(c);
}
using (ClientContext context = new ClientContext(url))//https://orgname.sharepoint.com/sites/MainListSite"
{
context.Credentials = new SharePointOnlineCredentials(username, Password);
List list = context.Web.Lists.GetByTitle("FirstMainList");//list name
context.Load(list);
context.ExecuteQuery();
Microsoft.SharePoint.Client.View view = list.Views.GetByTitle("All Items");//view name
context.Load(view);
context.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml = view.ViewQuery;
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();
//Console.WriteLine("Total Count: " + items.Count);
foreach (Microsoft.SharePoint.Client.ListItem itm in items)
{
Label1.Text = itm["Title"].ToString() + itm["Mobile"].ToString();
}
}
}
catch (Exception ex)
{
Label1.Text = "Exception " + ex.Message;
}
}
{
try
{
SecureString Password = new SecureString();
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
foreach (char c in "password")
{
Password.AppendChar(c);
}
using (ClientContext context = new ClientContext(url))//https://orgname.sharepoint.com/sites/MainListSite"
{
context.Credentials = new SharePointOnlineCredentials(username, Password);
List list = context.Web.Lists.GetByTitle("FirstMainList");//list name
context.Load(list);
context.ExecuteQuery();
Microsoft.SharePoint.Client.View view = list.Views.GetByTitle("All Items");//view name
context.Load(view);
context.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml = view.ViewQuery;
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();
//Console.WriteLine("Total Count: " + items.Count);
foreach (Microsoft.SharePoint.Client.ListItem itm in items)
{
Label1.Text = itm["Title"].ToString() + itm["Mobile"].ToString();
}
}
}
catch (Exception ex)
{
Label1.Text = "Exception " + ex.Message;
}
}
No comments:
Post a Comment