예제 #1
0
        /// <summary>
        /// Used to create a User Object to SharePointUser
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static SharePointUser BaseSetUser(ClientContext ctx, ListItem item, string field)
        {
            SharePointUser _owner = new SharePointUser();
            var _fieldUser = ((FieldUserValue)(item[field]));
            User _user = ctx.Web.EnsureUser(_fieldUser.LookupValue);
            ctx.Load(_user, u => u.LoginName, u => u.Email, u => u.PrincipalType, u => u.Title);
            ctx.ExecuteQuery();

            _owner.Email = _user.Email;
            _owner.Login = _user.LoginName;
            _owner.Name = _user.Title;

            return _owner;
        }
예제 #2
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
            string newWebUrl = string.Empty;
            using (ClientContext ctx = spContext.CreateUserClientContextForSPHost())
            {

                SharePointUser currentUser;
                ctx.Load(ctx.Web.CurrentUser);
                ctx.ExecuteQuery();

                var user = ctx.Web.CurrentUser;
                currentUser = new SharePointUser()
                {
                    Email = user.Email,
                    Login = user.LoginName,
                    Name = user.Title
                };


                var siteRequestInfo = new SiteRequestInformation()
                {
                    Title = this.txtTitle.Text,
                    Description = this.txtDescription.Text,
                    EnumStatus = SiteRequestStatus.New,
                    Template = "STS#0",
                    SiteOwner = currentUser,
                  
               
                };

                siteRequestInfo.Url = string.Format(@"{0}{1}", this.lblBasePath.Text, siteRequestInfo.Title);
                LabHelper _helper = new LabHelper();
                _helper.AddRequest(siteRequestInfo, ctx);
            }


            Response.Redirect(Page.Request["SPHostUrl"]);
        }