私のアプリケーションは自分のサイトでカレンダーを作成します。カスタム連絡先リストにある各人のビューを作成するビューをコードで作成しました。
連絡先リストには、ユーザー名 (私の場合は「開発者」) である「ユーザー」フィールドがあります。
アプリでビューを作成するとき、CAML を使用して、この連絡先のユーザー名/ログイン名によって作成されたすべてのイベントをフィルター処理します。しかし、ビューを選択し、新しいイベントを作成して保存すると、イベントはそのビューに表示されず、デフォルトの「カレンダー」ビューにのみ表示されます。
見逃したものは何ですか?CAML フィルターは、この連絡先ユーザー名によって作成されたこの新しいイベントを表示するべきではありませんか?
Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
{
Web web = clientContext.Web;
ListCreationInformation listCreator = new ListCreationInformation();
listCreator.Title = "CompanyCalendar";
listCreator.Description = "Workcalendar";
listCreator.TemplateType = (int)ListTemplateType.Events;
List ifListExcists;
// ValidateList() is a custo method to validate if the list already excists
if (!ValidateList(clientContext, listCreator.Title, out ifListExcists))
{
List calList = web.Lists.Add(listCreator);
clientContext.ExecuteQuery();
testLabel.Text = "The " + listCreator.Title + " list was created";
List contactList = web.Lists.GetByTitle("Contacts");
CamlQuery query = CamlQuery.CreateAllItemsQuery();
Microsoft.SharePoint.Client.ListItemCollection collection = contactList.GetItems(query);
clientContext.Load(collection);
clientContext.ExecuteQuery();
foreach (var thisPerson in collection)
{
List companyCalendarList = web.Lists.GetByTitle("CompanyCalendar");
Microsoft.SharePoint.Client.View view = companyCalendarList.Views.GetByTitle("Calendar");
clientContext.Load(view);
clientContext.ExecuteQuery();
//Find the username for this user in cantactlist
var loggedInUserName = thisPerson["loggedInUser"];
//Get to LastName of (Req field) in the contactlist just for testing
string currentUserName = thisPerson["Title"].ToString();
//Create a new CalendarView
ViewCreationInformation newView = new ViewCreationInformation();
newView.Title = currentUserName;
newView.Query = "<Where><Eq><FieldRef Name='Author' /><Value Type='User'>" + loggedInUserName + "</Value></Eq></Where>";
calList.Views.Add(newView);
clientContext.ExecuteQuery();
}
}
else
{
testLabel.Text = "List already excist";
}
}