0
我試圖讓只有指定從SharePoint列表值,所以我的代碼是這樣的:檢索特定項目
public List<MenuPrincipal> GetMenuOptions(string idioma)
{
List<MenuPrincipal> result = new List<MenuPrincipal>();
try
{
SecureString pwd = SPAccess.GetPasswordFromConsoleInput(Definitions.UserPassword);
using (var context = new ClientContext(Definitions.WebUrl))
{
context.Credentials = new SharePointOnlineCredentials(Definitions.UserName, pwd);
List listResult = context.Web.Lists.GetByTitle("MenuPrincipal");
//CamlQuery query = CamlQuery.CreateAllItemsQuery(1000);
CamlQuery query = new CamlQuery();
query.ViewXml = string.Format("<View><Query><Where><Eq><FieldRef Name='Idioma'/><Value Type='Text'>{0}</Value></Eq></Where></Query><RowLimit>1000</RowLimit></View>", idioma);
ListItemCollection items = listResult.GetItems(query);
context.Load(items);
context.ExecuteQuery();
foreach (ListItem item in items)
{
result.Add(new MenuPrincipal
{
Titile = item["Title"] == null ? string.Empty : item["Title"].ToString(),
Enlace = item["Enlace"] == null ? string.Empty : item["Enlace"].ToString(),
Posicion = item["Posicion"] == null ? 0 : Convert.ToInt32(item["Posicion"]),
Idioma = item["Idioma"] == null ? string.Empty : item["Idioma"].ToString(),
Funcion = item["Funcion"] == null ? string.Empty : item["Funcion"].ToString()
});
}
}
}
catch (Exception)
{
throw;
}
return result.OrderBy(x => x.Posicion).ToList();
}
但它得到的值了很多,而我只需要那些價值觀我的foreach,所以我嘗試做這樣的事情:
context.Load(
items,
lists => lists.Include(
list => list.Titile.
list => list.Enlace,
list => list.Posicion,
list => list.Idioma,
list => list.Funcion));
,而不是context.Load(items);
MSN Reference
誰能幫助我如何檢索特定的領域呢?問候