SharePoint - динамически изменяйте порог представления списка CodeBehind - PullRequest
0 голосов
/ 13 мая 2019

Мой текущий просмотр списка SP превышает пороговое ограничение, установленное в SP Central Admin:

enter image description here


Изменение предела с SPCA не являетсявариант для меня, так как он влияет на производительность других сайтов.

Вопрос: Как мне установить Порог просмотра списка просмотра динамически из кода позади?


Ниже мой код:

private static DataTable GenerateReport()
{
    DataTable dtAll = new DataTable();

    string subQuery = "<Neq><FieldRef Name =\"ContentType\"/><Value Type=\"Text\">{0}</Value></Neq>".FormatWith("Document");

    try
    {
        SPList recordDocument = SPHelper.GetListByUrl(ErmsConfig.GetString(ErmsConfig.Config.RecordDocument));

        SPView view = recordDocument.GetView(ErmsConfig.GetGuid(ErmsConfig.Config.RecordDocumentFilePlanReportListView));

        SPQuery query1 = new SPQuery(view)
        {
            RowLimit = 0,
        };

        Stopwatch tempWatch = new Stopwatch();

        tempWatch.Start();

        SPListItemCollection primaryHeaders = recordDocument.GetItems(query1);

        int itemCount = primaryHeaders.Count;

        tempWatch.Stop();

        tempWatch.Start();

        var distinctPrimaryHeaders = (from SPListItem item in primaryHeaders select item["Header1Ref"]).Distinct().ToList();

        tempWatch.Stop();

        Stopwatch primaryHeaderWatch = new Stopwatch();

        primaryHeaderWatch.Start();

        foreach (var primaryHeaderRef in distinctPrimaryHeaders)
        {
            try
            {
                Stopwatch folderWatch = new Stopwatch();
                folderWatch.Start();
                SPQuery query = new SPQuery(view)
                {
                    RowLimit = 0,

                    Query = "<Where><And><Eq><FieldRef Name =\"Header1Ref\"/><Value Type=\"Text\">{0}</Value></Eq>{1}</And></Where>".FormatWith(primaryHeaderRef, subQuery),
                    ViewAttributes = "Scope=\"RecursiveAll\"",
                    ViewFields = @"
                        <FieldRef Name='Header1Title'/>
                        <FieldRef Name='Header2Title'/>
                        <FieldRef Name='Header3Title'/>
                        <FieldRef Name='FolderTitle'/>
                        <FieldRef Name='FolderRef'/>
                        <FieldRef Name='BusinessOwner'/>
                        <FieldRef Name='RecordTitle'/>
                        <FieldRef Name='RecordLink'/>",
                };

                SPListItemCollection filePlanListing = recordDocument.GetItems(query);

                DataView dv = new DataView(filePlanListing.GetDataTable());

                dv.Sort = "Header1Title, Header2Title, Header3Title";

                dtAll.Merge(dv.ToTable());

                folderWatch.Stop();
            }
            catch(Exception ex)
            {
                Log(ex.ToString());
            }
        }

        primaryHeaderWatch.Stop();
    }
    catch(Exception ex)
    {
        throw;
    }

    return dtAll;
}

Ниже приведен пример кода управления пороговым значением.Я пытался изменить и интегрировать в мой код, но не смог ..

string strQueryMass = @"<Or>
                            <And>
                                <And>
                                    <And>IDPLACEHOLDER</And>
                                    <Eq><FieldRef Name='ContentType' /><Value Type='Text'>ERMS Header Content Type</Value></Eq>
                                </And>
                                <Eq><FieldRef Name='HeaderRef' /><Value Type='Text'>" + strReference + @"</Value></Eq>
                            </And>
                            <And>
                                <And>
                                    <And>IDPLACEHOLDER</And>
                                    <Eq><FieldRef Name='ContentType' /><Value Type='Text'>ERMS Folder Content Type</Value></Eq>
                                </And>
                                <Eq><FieldRef Name='FolderRef' /><Value Type='Text'>" + strReference + @"</Value></Eq>
                            </And>
                        </Or>";
DataTable spliTemp = NoThresholdQuery(MassCreateFolderList, "", "", "<Where>"+strQueryMass+"</Where>");




public DataTable NoThresholdQuery(SPList CIList, string strViewFields, string strViewAttributes, string strQuery)
{

    SPQuery lastIDQuery = new SPQuery();
    lastIDQuery.RowLimit = 1;
    lastIDQuery.ViewFields = "<FieldRef Name='ID' />";
    lastIDQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
    lastIDQuery.ViewAttributes = "Scope='RecursiveAll'";

    SPListItemCollection LastIDItems = CIList.GetItems(lastIDQuery);

    uint ROWLIMIT = 1000;
    int intTotalLoops = 0;
    if (LastIDItems[0] != null)
    {
        double dblLastID = Convert.ToDouble(LastIDItems[0]["ID"].ToString());
        intTotalLoops = Convert.ToInt32(Math.Ceiling(dblLastID / ROWLIMIT));
    }
    DataTable resultCollection = new DataTable();

    if (intTotalLoops != 0)
    {
        try
        {
            for (int intLoopCounter = 0; intLoopCounter < intTotalLoops; intLoopCounter++)
            {

                SPQuery listQuery = new SPQuery();
                string strListQuery = strQuery;
                strListQuery = strListQuery.Replace("IDPLACEHOLDER", "<Geq><FieldRef Name='ID' /><Value Type='Integer'>" + ROWLIMIT * (intLoopCounter) + "</Value></Geq><Lt><FieldRef Name='ID' /><Value Type='Integer'>" + ROWLIMIT * (intLoopCounter + 1) + "</Value></Lt>");

                listQuery.RowLimit = ROWLIMIT;
                if (strViewAttributes != "")
                {
                    listQuery.ViewAttributes = strViewAttributes;
                }
                if (strViewFields != "")
                {
                    listQuery.ViewFields = strViewFields;
                    listQuery.ViewFieldsOnly = true;
                }
                listQuery.Query = strListQuery;
                SPListItemCollection items = CIList.GetItems(listQuery);

                if (items.Count > 0)
                {
                    DataTable dTable1 = items.GetDataTable();
                    if (dTable1 != null)
                    {
                        resultCollection.Merge(dTable1);
                    }
                }
            }
            return resultCollection;
        }
        catch (Exception ex)
        {
            ex.AddData("Error", "Exception", "Exception", ex.ToString());
            throw;
        }
    }
    else
    {
        return resultCollection;
    }
}

Любая помощь будет принята с благодарностью.

...