我有一种情况,我必须根据记录是否有打开或关闭的项目将源记录列表状态列更新为打开或关闭状态 - 项目列表可以通过源项目的ID和项目中的客户端ID将多个项目链接到源记录,代码是检索客户项目,然后检查是否有结束日期,如果没有 - 它的开放 - 如果有的话 - 它的封闭。这些sharepoint列表很大Sharepoint 2010 - 更新大列表,处理非常缓慢和超时
我已经写了代码,基本上允许我指定一个开始ID,然后它会在停止之前处理这么多的记录,当我点击一个运行按钮时 - 我把这个放到位,因为这个过程非常缓慢甚至超时,但我不明白为什么它如此缓慢和不稳定 - 如果我尝试处理超过150条记录 - 超时,服务器本身是一个带有24GB内存的八核系统,所以我不会不认为它的服务器,它可能是我的代码。
protected void Button1_Click(object sender, EventArgs e)
{
SPWeb web = SPControl.GetContextWeb(this.Context);
string SPsiteUrl = SPContext.Current.Web.Url;
Label1.Text = "Running";
int start;
start = Convert.ToInt32(TextBox1.Text);
start = int.Parse(TextBox1.Text);
int end = start + 150;
int count = 0;
using (SPSite oSite = new SPSite(SPsiteUrl))
{
using (SPWeb oWeb = oSite.OpenWeb("/Client"))
{
// get lists
SPList oList = oWeb.Lists["Source Records"];
SPList pList = oWeb.Lists["Project"];
// query Source Records
string sQuery = @"<Where><And><Geq><FieldRef Name='ID' /><Value Type='Number'>" + start + "</Value></Geq><Leq><FieldRef Name='ID'/><Value Type='Number'> "+ end +"</Value></Leq></And></Where>";
string sViewFields = @"<FieldRef Name='ID' />";
string sViewAttrs = @"Scope=""Recursive""";
uint iRowLimit = 0;
var oQuery = new SPQuery();
oQuery.Query = sQuery;
oQuery.ViewFields = sViewFields;
oQuery.ViewAttributes = sViewAttrs;
oQuery.RowLimit = iRowLimit;
SPListItemCollection collListItems = oList.GetItems(oQuery);
// for each item
foreach (SPListItem oListItem in collListItems)
{
// get the client id
int id = oListItem.ID;
count = count + 1;
//Label1.Text = "Checking record" + id;
bool isopen = false;
// for each client id access the projects list
// query the closed date
string Query = @"<Where><Eq><FieldRef Name=""Client_x003a_ID"" /><Value Type=""Text"">" + id + "</Value></Eq></Where>";
string pViewFields = @"<FieldRef Name=""End_x0020_Date"" />";
string pViewAttrs = @"Scope=""Recursive""";
uint pRowLimit = 0;
var pQuery = new SPQuery();
pQuery.Query = Query;
pQuery.ViewFields = pViewFields;
pQuery.ViewAttributes = pViewAttrs;
pQuery.RowLimit = pRowLimit;
SPListItemCollection ListItems = pList.GetItems(pQuery);
foreach (SPListItem ListItem in ListItems)
{
try
{
DateTime enddate = (DateTime)ListItem["End_x0020_Date"];
if (enddate != null)
{
isopen = false;
}
// else if the date is null set the open to true
else
{
isopen = true;
}
}
catch
{
string enddate = null;
if (enddate == null)
{
// if the end date is present set project closed to true
isopen = true;
}
}
// if project is open
if (isopen)
{
oWeb.AllowUnsafeUpdates = true;
SPListItem itemupdate = oWeb.Lists["Source Records"].Items.GetItemById(id);
itemupdate["Status"] = "Open";
itemupdate.Update();
oWeb.AllowUnsafeUpdates = false;
// set records on source record to open
}
//else // project is closed
//{
// oWeb.AllowUnsafeUpdates = true;
// SPListItem itemupdate = oWeb.Lists["Source Records"].Items.GetItemById(id);
// itemupdate["Status"] = "Closed";
// itemupdate.Update();
// oWeb.AllowUnsafeUpdates = false;
// // set the record to closed
//}
}
}
Label1.Text = "Finished Number of records checked: " + count + " of " + collListItems.Count;
}
}
}'
的代码被编码后的文件从WSP拉 - 已经编辑到包括整个代码,包括注释掉的代码 – Carl