そのため、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 回呼び出します。
すべてのロード ステートメントを 1 つのステートメントにまとめようとしましたが、成功しませんでした。
3つのステートメントを1つのステートメントに入れる方法、またはデータを取得するためのより優れた高速な方法を知っている人はいますか?
記録のために: 私は SharePoint CLIENT オブジェクト モデルを使用しています。
答えを楽しみにしています!