我当前的SP列表视图超出了SP Central Admin中设置的阈值限制:
更改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;
}
}
任何帮助将不胜感激。