5d6d网 发表于 2015-9-26 12:12:02

SharePoint Server 2007 Membership初体验

由此了解到SharePoint Server 2007 新增了一些Object Model支持User Profile Store,其中一个是Memebership。
有了这些Object Model可以在程序中很方便的管理SharePoint站点的用户信息、权限,包括添加修改用户信息、添加修改用户组。

在SharePoint Server 2007中创建了site,亲手试验文档给出的Exmaple,发现运行到
UserProfileManager profileManager = newUserProfileManager(context);
抛出异常Value cannot be null.Parameter name: serverContext

跟踪后发现是
ServerContext context = ServerContext.GetContext(site);
返回了null而引起的,但不知何故?这是一个创建Membership的Example:


using (SPSite site = new SPSite("http://servername"))
            {
                   ServerContext context =
                     ServerContext.GetContext(site);
                  UserProfileManager profileManager =
                      new UserProfileManager(context);
               
                //Create a member group
               MemberGroup newGroup =
                     profileManager.GetMemberGroups().
                     CreateMemberGroup(PrivacyPolicyIdConstants.
                     MembershipsFromDistributionLists,
                     "Customer Connection Team","Customer Connection VTeam","Customer Connection","http://example","abcd");
               
                //Create a membership
               string sAccount = "domainname\\username";
                UserProfile u = profileManager.GetUserProfile(sAccount);
                u.Memberships.Create(newGroup,
                  MembershipGroupType.UserSpecified,
                  "Customer Connection Team", Privacy.Organization);
               }
            }

反复试验了几个Example都是一样的结果。希望高手指点!
页: [1]
查看完整版本: SharePoint Server 2007 Membership初体验