共用方式為


Rollup Site Content

SPWeb web = null;

SPList list = null;

// try to open the site sites/lschome/apps/applications/Lists/Ex/AllItems.aspx

try

{

string siteUrl = "/sites/lschome/apps/applications";

web = SPContext.Current.Site.OpenWeb(siteUrl);

}

catch (Exception ex)

{

string message = @"Could not open site with specified URL. Make sure you enter a server relative URL, which means don't include the https://servername part.";

ApplicationException newException = new ApplicationException(message, ex);

throw newException;

}

// try to get the list

try

{

web.AllowUnsafeUpdates = true;

string listUrl = web.ServerRelativeUrl + "/Lists/Ex/AllItems.aspx";

list = web.GetListFromUrl(listUrl);

foreach (SPListItem item in list.Items)

{

string ts = item[":"].GetType().ToString();

Type t = item[":"].GetType();

SPFieldLookup appNameFieldValue = item["Application Name"] as SPFieldLookup;

if (appNameFieldValue == null || string.IsNullOrEmpty(appNameFieldValue.ToString()))

{

string urlFieldValue = item[":"] as string;

int firstComma = urlFieldValue.IndexOf(',');

string tempAppName = urlFieldValue.Substring(firstComma + 2);

string lookupListUrl = web.ServerRelativeUrl + "/Lists/Applications%20List/AllItems.aspx";

SPList lookupList = web.GetListFromUrl(lookupListUrl);

foreach (SPListItem lookupItem in lookupList.Items)

{

if (lookupItem["Application Name"].ToString() == tempAppName)

{

item["Application Name"] = new SPFieldLookupValue(lookupItem.ID, tempAppName);

item.Update();

}

}

//item["Application Name"] = appName;

//item.Update();

}

}

}

catch (Exception ex)

{

string message = @"Could not open experts list.";

ApplicationException newException = new ApplicationException(message, ex);

throw newException;

}