提供程序托管的应用程序日历视图,添加事件后视图不会更新



我的应用程序在我的站点上创建了一个日历,我在代码中创建了一个视图,为我的自定义联系人列表中的每个人创建一个视图。

在我的联系人列表中,我有一个"User"字段,这是我的用户名(在我的情况下是"Developer")。

当我在我的应用程序中创建一个视图时,我使用CAML来过滤这个联系人用户名/登录名创建的所有事件。但当我选择一个视图,创建一个新事件并保存时,事件不会显示在那个视图中,它只显示在默认的Calendar视图中。

a错过了什么?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";
            }
        }

这样做,它将工作!

var loggedInUserName = thisPerson["loggedInUser"] as Microsoft.SharePoint.Client.FieldLookupValue;
int userId = loggedInUserName.LookupId;
//Create a new CalendarView
ViewCreationInformation newView = new ViewCreationInformation();
newView.Query = "<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Lookup'>" + userId + "</Value></Eq></Where>";

相关内容

  • 没有找到相关文章

最新更新