Hi @Mohammad Qasim ,
Just use LINQ to list.getitmes(ospquery). Like this:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Greetings,
i have data into list like below,i want to count progrmatically using c#
ID, User ID UserName, Documentname
1 5 A Test
2 5 A Testa
3 6 B Testb
4 7 C Testc1
5 7 C Testc
6 8 AB Testabd
Requirement
I want "count" document, based on user on desc order, so output would be like this
Name, Total Docs
A 2
B 1
C 2
AB 1
hi, do you have SP on-prem or SP online? For on-prem you may use basic server object model for your need:
var web = ...;
var list = web.Lists["MyList"];
var dict = new Dictionary<int, int>();
foreach (SPListItem item in list.Items)
{
int userId = (int)item["User ID"];
if (!dict.ContainsKey(userId))
{
dict.Add(userId, 0);
}
dict[userId]++;
}
After that dictionary will have necessary date: user ids and count of list items. You may put it to report or to other Sharepoint list. If you will need to add user name you may get it from web.SiteUsers.GetByID(userId) call.
yes I have sp2016 on prem ,how to count and distint or group by ?
do u have any example to be shared ??
You could use LINQ to SharePoint List items to achieve this. Below is my demo code for you: demo.txt
Below is my test result:
Test List
Output
If the response is helpful, please click "Accept Answer" and upvote it.
I have spquery object , where I have written query to pass into list.getitmes(ospquery).
using spquery , how to do above method ( as u shared example above ) ?