因此,我正在开发一个与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进行3次调用SharePoint网站,以获取所需的数据。
我试图将所有装入语句放在一个语句中,但是没有成功。
有人知道如何将3条语句放在一条语句中,或者一种更好更快的方法来检索数据吗?
对于记录:我正在使用SharePoint CLIENT对象模型。
期待答案!
最佳答案
我认为您需要更改在此处获取数据的基本方法。
鉴于您希望从不确定数量的列表中收集数据,因此在所有可能位于任何列表中的公告之后,您都应该使用其他数据访问API搜索。认真地说,搜索对您来说会快得多。
要在网站上获得所有公告,您的查询将变得简单而漂亮,您只需向http://SiteUrl/_api/search/query?querytext=%27ContentTypeId:0x01*%27
发出请求
只需在网络浏览器中点击该按钮,即可查看结果的形状。
Tobias Zimmergren和Chris O'Brien关于使用REST Search API的博客文章很棒。这种方法确实具有局限性,即结果仅与上一次搜索爬网一样新鲜,但是它却更快,更高效
关于c# - 从SharePoint下载数据的最佳方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19687399/