Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // define initial script, needed to render the chrome control
            string script = @"
            function chromeLoaded() {
                $('body').show();
            }

            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'
                };

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);
                chromeNavigation.setVisible(true);
            }";

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);

            if (!Page.IsPostBack)
            {
                // prefil people pickers with current user
                var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
                using (var clientContext = spContext.CreateUserClientContextForSPHost())
                {
                    clientContext.Load(clientContext.Web, web => web.Title, user => user.CurrentUser);
                    clientContext.ExecuteQuery();
                    Microsoft.SharePoint.Client.User currentUser = clientContext.Web.CurrentUser;

                    //fill json meoplepicker
                    List <PeoplePickerUser> peoplePickerUsers = new List <PeoplePickerUser>(1);
                    peoplePickerUsers.Add(new PeoplePickerUser()
                    {
                        Name = currentUser.Title, Email = currentUser.Email, Login = currentUser.LoginName
                    });
                    hdnAdministrators.Value = JsonHelper.Serialize <List <PeoplePickerUser> >(peoplePickerUsers);

                    //fill csom peoplepicker
                    PeoplePickerHelper.FillPeoplePickerValue(hdnCsomAdministrators, currentUser);
                }
            }
        }
Ejemplo n.º 2
0
        protected void btnGetValueByServer_Click(object sender, EventArgs e)
        {
            //get values from csom peoplepicker
            List <PeoplePickerUser> users = PeoplePickerHelper.GetValuesFromPeoplePicker(hdnCsomAdministrators);

            string parsedResult = "";

            foreach (var user in users)
            {
                if (parsedResult.Length > 0)
                {
                    parsedResult = parsedResult + "," + user.Name;
                }
                else
                {
                    parsedResult = user.Name;
                }
            }

            this.lblCsomEnteredData.Text = parsedResult;
        }
Ejemplo n.º 3
0
 public static string GetPeoplePickerData()
 {
     //peoplepickerhelper will get the needed values from the querrystring, get data from sharepoint, and return a result in Json format
     return(PeoplePickerHelper.GetPeoplePickerSearchData());
 }