Domanda

Il mio codice è piuttosto semplice. Creo una lista di calendari e alcune viste per il calendario.

Creo una vista per ciascun contatto nell'elenco dei contatti personalizzato (contenente un campo "utente" che contiene il nome utente di login di quella persona).

Tutto ciò viene creato quando avvio la mia APP Provider Hosted APP .

La cosa è che quando aggiungo un evento del calendario dovrei essere in grado di vedere quell'evento a mio avviso. Nel mio campo utente del calendario personalizzato ho aggiunto il mio nome utente "sviluppatore" nel mio caso. (Vedi immagine)

Inserire l'immagine Descrizione qui

     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 custom 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";

                //Get my custom contactlist that contains a User field that contains the login username of that contact
                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)
                {
                    //Find the username for this user in cantactlist
                    var loggedInUserName = thisPerson["loggedInUser"];

                    //Get the internal name for LastName field (Which is the only Required field in this list) in the contactlist just for testing
                    string currentUserName = thisPerson["Title"].ToString();

                    //Create a new CalendarView
                    ViewCreationInformation newView = new ViewCreationInformation();
                    newView.Title = currentUserName;
                    //Show events that a re "created by"(Author) thisPerson["loggedInUser"]
                    newView.Query = "<Where><Eq><FieldRef Name='Author' /><Value Type='User'>" + loggedInUserName + "</Value></Eq></Where>";

                    calList.Views.Add(newView);
                    clientContext.ExecuteQuery();
                }

            }
            else
            {
                //I don't think I need this but I post it just to show that its still not working even though I try to update the views.
                Microsoft.SharePoint.Client.ViewCollection viewCollection = web.Lists.GetByTitle("CompanyCalendar").Views;
                clientContext.Load(viewCollection);
                clientContext.ExecuteQuery();
                foreach (Microsoft.SharePoint.Client.View view in viewCollection)
                {
                    view.Update();
                    clientContext.ExecuteQuery();
                }
                testLabel.Text = "List already excist";
            }
        }
.

Questo spettacolo dopo aver aggiunto un evento registrato come "sviluppatore" (che è il nome utente all'interno di "Bergsten" -View).

Inserire l'immagine Descrizione qui

La mia domanda: Perché questa vista non mostra gli eventi che sto aggiungendo? Mostrano in default la vista del calendario ma non questa "Bergsten" -View. Il filtraggio della camm non sembra funzionare. C'è qualcosa che mi manca o è qualcosa di sbagliato con il mio view.Query?

È stato utile?

Soluzione

puoi provare in questo modo:

var loggedInUserName = thisPerson["loggedInUser"] as Microsoft.SharePoint.Client.FieldLookupValue;
int userId = loggedInUserName.LookupId;

//Create a new CalendarView
ViewCreationInformation newView = new ViewCreationInformation();

//Show events that are "created by"(Author) thisPerson["loggedInUser"]
newView.Query = "<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Lookup'>" + userId + "</Value></Eq></Where>";
.

Questo dovrebbe funzionare ..

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top