0

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

在我的联系人列表中,我有一个“用户”字段,它是我的用户名(在我的例子中是“开发人员”)。

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

1 回答 1

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>";
于 2014-06-03T23:25:27.557 回答