Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

                using (var clientContext = spContext.CreateUserClientContextForSPHost())
                {
                    clientContext.Load(clientContext.Web, web => web.CurrentUser);
                    clientContext.ExecuteQuery();

                    //Prefil the current user information
                    Microsoft.SharePoint.Client.User currentUser       = clientContext.Web.CurrentUser;
                    List <SharePointUser>            peoplePickerUsers = new List <SharePointUser>(1);
                    peoplePickerUsers.Add(new SharePointUser()
                    {
                        displayName = currentUser.Title,
                        text        = currentUser.Title,
                        email       = currentUser.Email,
                        isResolved  = false,
                        loginName   = currentUser.LoginName
                    });
                    txtSiteOwner.Text = JsonUtility.Serialize <List <SharePointUser> >(peoplePickerUsers);
                }
            }
        }
 public SPUserPrincipal(User user)
 {
     Id = user.Id;
     LoginName = user.LoginName;
     DisplayName = user.Title;
     Email = user.Email;
 }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        public string Get()
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext.Current);

            Microsoft.SharePoint.Client.User spUser = null;
            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                if (clientContext != null)
                {
                    spUser = clientContext.Web.CurrentUser;

                    clientContext.Load(spUser, user => user.Title);

                    clientContext.ExecuteQuery();
                }
            }
            return("Executing User: " + spUser.Title);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Default Index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            Microsoft.SharePoint.Client.User spUser = null;

            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                if (clientContext != null)
                {
                    spUser = clientContext.Web.CurrentUser;

                    clientContext.Load(spUser, user => user.Title);

                    clientContext.ExecuteQuery();

                    ViewBag.UserName = spUser.Title;
                }
            }

            return(View());
        }
Exemplo n.º 6
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");
            string account = req.GetQueryNameValuePairs()
                             .FirstOrDefault(q => string.Compare(q.Key, "account", true) == 0)
                             .Value;
            // Get request body
            UserProfile data = await req.Content.ReadAsAsync <UserProfile>();

            string authenticationToken = await helper.getSharePointToken(log, ConfigurationManager.AppSettings["tenantURL"]);

            if (account != null)
            {
                try
                {
                    using (var clientContext = helper.GetClientContext(ConfigurationManager.AppSettings["tenantURL"], authenticationToken))
                    {
                        PeopleManager peopleManager = new PeopleManager(clientContext);
                        clientContext.Load(peopleManager);
                        if (data.jobTitle != null && data.jobTitle != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "Title", data.jobTitle);
                        }
                        if (data.employeeID != null && data.employeeID != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "EmployeeID", data.employeeID);
                        }
                        if (data.employeeType != null && data.employeeType != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "EmployeeType", data.employeeType);
                        }
                        if (data.workPhone != null && data.workPhone != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "WorkPhone", data.workPhone);
                        }
                        if (data.department != null && data.department != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "Department", data.department);
                        }
                        if (data.taxonomyDepartment != null && data.taxonomyDepartment != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "TaxonomyDepartment", data.taxonomyDepartment);
                        }
                        if (!string.IsNullOrEmpty(data.officeNumber))
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "OfficeNumber", data.officeNumber);
                        }

                        if (data.manager.email != null && data.manager.email != "")
                        {
                            string managerAccount = "i:0#.f|membership|" + data.manager.email;
                            Microsoft.SharePoint.Client.User mngr = await helper.getSPUser(managerAccount, clientContext, log);

                            peopleManager.SetSingleValueProfileProperty(account, "Manager", mngr.LoginName);
                        }
                        if (data.cellPhone != null && data.cellPhone != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "CellPhone", data.cellPhone);
                        }
                        if (data.officeRegion != null && data.officeRegion != "")
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "Office", data.officeRegion);
                        }
                        if (!string.IsNullOrEmpty(data.accountExpiration))
                        {
                            peopleManager.SetSingleValueProfileProperty(account, "AccountExpiration", data.accountExpiration.ToString());
                        }
                        if (data.countrySpecialities != null)
                        {
                            List <string> countries = new List <string>();
                            foreach (var country in data.countrySpecialities)
                            {
                                countries.Add(country);
                            }
                            peopleManager.SetMultiValuedProfileProperty(account, "CountrySpecialities", countries);
                        }
                        if (data.industrySpecialities != null)
                        {
                            List <string> industries = new List <string>();
                            foreach (var industry in data.industrySpecialities)
                            {
                                industries.Add(industry);
                            }

                            peopleManager.SetMultiValuedProfileProperty(account, "IndustrySpecialities", industries);
                        }

                        if (data.education != null)
                        {
                            string strEducation = "";
                            foreach (Education edu in data.education)
                            {
                                strEducation += "{schoolName:\"" + edu.schoolName + "\",degree:\"" + edu.degree + "\",year:\"" + edu.year + "\"}#;";
                            }
                            peopleManager.SetSingleValueProfileProperty(account, "Education", strEducation);
                        }

                        if (data.certifications != null)
                        {
                            string strCerification = "";
                            foreach (Certification cert in data.certifications)
                            {
                                strCerification += "{organization:\"" + cert.organization + "\",title:\"" + cert.title + "\",year:\"" + cert.year + "\"}#;";
                            }
                            peopleManager.SetSingleValueProfileProperty(account, "Certifications", strCerification);
                        }

                        if (data.emergencyContactInformation != null)
                        {
                            string strContacts = "";
                            foreach (Contact contact in data.emergencyContactInformation)
                            {
                                strContacts += "{firstName:\"" + contact.firstName + "\",lastName:\"" + contact.lastName + "\",phoneNumber:\"" + contact.phoneNumber + "\",emailAddress:\"" + contact.emailAddress + "\"}#;";
                            }
                            peopleManager.SetSingleValueProfileProperty(account, "EmergencyContacts", strContacts);
                        }

                        if (data.mailingAddress != null)
                        {
                            string mailingAddress = data.mailingAddress.addressLine1 + "#;" + data.mailingAddress.addressLine2 + "#;" + data.mailingAddress.city + "#;" + data.mailingAddress.state + "#;" + data.mailingAddress.zipCode + "#;" + data.mailingAddress.country;
                            peopleManager.SetSingleValueProfileProperty(account, "MailingAddress", mailingAddress);
                        }
                        clientContext.ExecuteQuery();
                        log.Info("First Name : " + data.firstName + data.lastName);
                        var response = req.CreateResponse(HttpStatusCode.OK);
                        response.Content = new StringContent("{\"status\":\"Success\"}", Encoding.UTF8, "application/json");
                        return(response);
                    }
                }
                catch (Exception ex)
                {
                    var response = req.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent("{\"status\":\"Error\",\"message\":\"" + ex.Message + "\"}", Encoding.UTF8, "application/json");
                    return(response);
                }
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please provide valid ITA account"));
            }
        }