class Program
{
static string baseurl = "https://<SiteURL>";
static void Main(string[] args)
{
string eval1 = "1";
string eval2 = "1000";
int zerocount = 0;
ClientContext ctx = new ClientContext(baseurl);
List spList = ctx.Web.Lists.GetByTitle(<List Name>);
ctx.Load(spList);
ctx.ExecuteQuery();
IList<MyClass> reslist = new List<MyClass>();
string caml = "";
int counter = 0;
int ItemCnt = spList.ItemCount;
if (spList != null && spList.ItemCount > 0)
{
do
{
// Query where the ID is between the start & end values
CamlQuery camlQuery = new CamlQuery();
caml = string.Format(@"<View>
<Query>
<Where>
<And>
<Geq><FieldRef Name='ID' /><Value Type='Counter'>{0}</Value></Geq>
<Leq><FieldRef Name='ID' /><Value Type='Counter'>{1}</Value></Leq>
</And>
</Where>
</Query>
<ViewFields>
<FieldRef Name='ID' />
<FieldRef Name='Col2' />
<FieldRef Name='Col2' />
</ViewFields>
<RowLimit>5000</RowLimit>
</View>", eval1, eval2);
camlQuery.ViewXml = caml;
ListItemCollection listItems = spList.GetItems(camlQuery);
ctx.Load(listItems);
ctx.ExecuteQuery();
if (listItems.Count != 0)
{
zerocount = 0;
foreach (ListItem it in listItems)
{
counter++;
if (it.FieldValues["ID"] != null)
{
reslist.Add(new MyClass()
{
ID = Convert.ToString(it.FieldValues["ID"]),
COL2 = Convert.ToString(it.FieldValues["Col1"]),
COL3 = Convert.ToString(it.FieldValues["Col2"])
});
}
}
}
else
{
zerocount++;
}
eval1 = increment(eval1, 1000);
eval2 = increment(eval2, 1000);
} while (zerocount < 1);
int i = 1;
Console.WriteLine("Total Items - " + reslist.Count);
foreach (var itm in reslist)
{
Console.WriteLine(i + ") " + itm.ID + " - " + itm.COL2 + " - " + itm.COL3);
i = i + 1;
}
Console.ReadKey();
}
}
public static string increment(string val1, int val2)
{
int tval1 = Convert.ToInt32(val1);
tval1 += val2;
return tval1.ToString();
}
}
public class MyClass
{
public string ID { get; set; }
public string COL2{ get; set; }
public string COL3 { get; set; }
}
No comments:
Post a Comment