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

时间:2014-06-03 11:07:35

标签: sharepoint sharepoint-2013 csom sharepoint-apps

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

在我的联系人列表中,我有一个“用户”字段,这是我的用户名(在我的情况下是“开发人员”)。

当我在我的应用程序中创建视图时,我使用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";
            }
        }

1 个答案:

答案 0 :(得分:0)

这样做会有效!

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>";
相关问题