I need to assign a filtered list to another list, however I do not know the list structure that will filter, just know the parameter for the filter. It Only returns an SPListItemCollection and I need to return a SPList.
Below follows method in which capture the list, I need to return a list, but filtered by query:
/// <summary>
/// reads the list to display
/// </summary>
/// <returns></returns>
public SPList GetListFromProjectWorkSpace()
{
SPList list = null;
Guid projUID = _helper.GetProjUID();
if (projUID == Guid.Empty)
{
return list;
}
// read project data
IProjectWssInfoDataSet dataset = _service.ReadWssData(projUID);
if (dataset.ProjWssInfo.Count == 0)
{
return list;
}
// get workspace name and url
string workspaceName = dataset.ProjWssInfo[0].WorkspaceName;
string workspaceUrl = dataset.ProjWssInfo[0].WorkspaceUrl;
SPSecurity.RunWithElevatedPrivileges(()=>
{
usi开发者_JAVA技巧ng (SPSite site = new SPSite(workspaceUrl))
{
for (int i = 0; i < site.AllWebs.Count; i++)
{
if (!site.AllWebs[i].ServerRelativeUrl.Contains(workspaceName))
{
continue;
}
try
{
list = site.AllWebs[i].Lists[SelectedList];
}
catch
{
}
}
SPQuery query = new SPQuery();
query.Query = @"<Where>
<Contains>
<FieldRef Name='LinkFilenameNoMenu' />
<Value Type='Computed'>work</Value>
</Contains>
</Where>";
SPListItemCollection itens = list.Items.List.GetItems(query);
// I need help here
}
});
return list;
}
att,
Eduardo
There is no method to “assign a list into another list”. You have to understand the fundamental distinction between list metadata and list content (items):
SPList
represents the metadata of a list;SPListItemCollection
contains particular items of a list — its data.
In case you need to copy the (filtered) content of one list into another list, you have to understand the structures (permitted content types, fields) of both lists and copy the items one by one (with possible data transformations).
Note: to get the list's metadata knowing a collection of its items, there the SPListItemCollection.List
property.
精彩评论