Answers for "get all items from sharepoint list c# csom"

C#
0

c# sharepoint get list item query

using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
    class RetrieveListItems
    {
        static void Main()
        {
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                "<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in collListItem)
            {
                Console.WriteLine("ID: {0} nTitle: {1} nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);
            }
        }
    }
}
Posted by: Guest on April-13-2021
0

sharepoint c# csom get list item attachment

using Microsoft.SharePoint.Client;
using System.Linq;
 
using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
// clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
// This value is NOT List internal name
List targetList = clientContext.Web.Lists.GetByTitle("List Name");
 
// Option 1: Get Item by ID
ListItem oItem = targetList.GetItemById(11);
 
// Option 2: Get Item using CAML Query
CamlQuery oQuery = new CamlQuery();
oQuery.ViewXml = @"<View><Query><Where>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>New List Item</Value>
</Eq>
</Where></Query></View>";
 
ListItemCollection oItems = targetList.GetItems(oQuery);
clientContext.Load(oItems);
clientContext.ExecuteQuery();
 
oItem = oItems.FirstOrDefault();
// Option 2: Ends Here(Above line)
 
AttachmentCollection oAttachments = oItem.AttachmentFiles;
clientContext.Load(oAttachments);
clientContext.ExecuteQuery();
 
foreach (Attachment oAttachment in oAttachments)
{
Console.WriteLine("File Name - " + oAttachment.FileName);
}
}
Posted by: Guest on April-20-2021

Code answers related to "get all items from sharepoint list c# csom"

C# Answers by Framework

Browse Popular Code Answers by Language