none
CAML query to find duplicate entry

All replies

  • Here are the information

    https://stackoverflow.com/questions/22569429/how-can-i-get-only-unique-field-values-from-a-sharepoint-csom-query


    Please remember to click Mark as Answer on the answer if it helps you

    Friday, November 9, 2018 11:22 PM
  • Hi,

    You could groupby the data by column records and find the count larger than 1.

    using (SPSite Site = new SPSite("siteURL"))
               {
                   using (SPWeb Web = Site.OpenWeb())
                   {
                       SPList list = Web.Lists.TryGetList("Test");
                       SPQuery query = new SPQuery(); // query for all the items
                       DataTable dt = list.GetItems(query).GetDataTable();
                       if (dt != null && dt.Rows.Count > 0)
                       {
                           var groupedList = from row in dt.AsEnumerable()
                           group row by row.Field<string>("MultiUsers") into groupedTable
                           orderby groupedTable.Key
                            select new
                               {   Key = groupedTable.Key,
                                    UserCount = groupedTable.Count(),
                                     groupedRows = groupedTable.CopyToDataTable()
                                };
     
                           DataTable dt1 = new DataTable();
                           dt1.Columns.Add("User Name", typeof(string));
                           dt1.Columns.Add("Count", typeof(int));
                           foreach (var items in groupedList)
                           {
                               string UserName = items.Key; //User Name
                               int count = items.UserCount; // count rows
                               DataRow dtRow = dt1.NewRow();
                               dtRow["User Name"] = UserName;
                               dtRow["Count"] = count;
                               dt1.Rows.Add(dtRow);
                           }
                           GridView1.DataSource = dt1;
                           GridView1.DataBind();
                 }}}

    Here is the thread for your reference.

    https://social.technet.microsoft.com/wiki/contents/articles/20298.count-or-groupby-list-item-based-on-person-or-group-column.aspx

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, November 12, 2018 1:39 AM
  • Good idea ~

    Please remember to mark the replies as answers if they helped.
    Linyu - SharePoint Engineer
    QQ Group: 72637444

    Monday, November 12, 2018 3:35 AM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, November 15, 2018 8:40 AM