所以,我正在开发一个与 SharePoint 2013 通信的 Windows 8.1 应用程序。
目前我正在使用以下方式下载数据:
public async Task<IList<NewsSite>> GetGroups(string vaultResource)
{
_clientContext.Credentials = new NetworkCredential(UserName, PassWord);
SP.Web site = _clientContext.Web;
ListCollection announcementListCollection = site.Lists;
_clientContext.Load(announcementListCollection);
List<NewsItem> NewsItems = new List<NewsItem>();
//load all news items wich are announcement items for all lists in the current site.
_clientContext.Load(announcementListCollection);
_clientContext.ExecuteQuery();
foreach (List sharePointGroup in announcementListCollection)
{
var ctypes = sharePointGroup.ContentTypes;
_clientContext.Load(ctypes);
_clientContext.ExecuteQuery();
if (ctypes.Where(c => c.Name == "Announcement").Count() == 1)
{
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>8</RowLimit></View>";
ListItemCollection newsListColl = sharePointGroup.GetItems(camlQuery);
_clientContext.Load(newsListColl,
eachItem => eachItem.Include(item => item.Id, item => item["Title"], item => item["Body"]));
_clientContext.ExecuteQuery();
foreach (ListItem NewsItem in newsListColl)
{
NewsItem newsItem = new NewsItem();
newsItem.Id = NewsItem.Id;
newsItem.Title = (string) NewsItem["Title"];
newsItem.Content = (string) NewsItem["Body"];
newsItem.ListHolder = sharePointGroup.Title;
string tempImageString = GetImageInHTML((string) NewsItem["Body"]);
var rgx1 = new Regex("http");
if (tempImageString != null)
{
var match = rgx1.Match(tempImageString);
if (match.Success)
{
newsItem.Image = Regex.Replace(tempImageString, ":", ":");
}
else
{
string pattern2 = @"http(s)?://(www\.)?\w*((.\w*)|(-*\w*))?(\.\w*)?";
var rgx2 = new Regex(pattern2);
string imgUrl = rgx2.Match(_siteUrl).ToString() + tempImageString;
newsItem.Image = imgUrl;
}
}
if (tempImageString == null)
{
newsItem.Image = null;
}
NewsItems.Add(newsItem);
}
}
}
var newsItemsBySite =
NewsItems.GroupBy(x => x.ListHolder).Select(x => new NewsSite {Title = x.Key, Items = x.ToList()});
return newsItemsBySite.ToList();
}
通过这种方式,应用程序对每个 ListItem 的 SharePoint 站点进行 3 次调用,以获取所需的数据。
我试图将所有加载语句放在一个语句中,但没有成功。
有谁知道如何将这 3 个语句放在一个语句中,或者以一种更好更快的方式来检索数据?
对于记录:我使用的是 SharePoint CLIENT 对象模型。
期待答案!