希望在明天

如果,你没有耐心等待成功的到来,那么,你将用一生的耐心去面对失败。

SharePoint Server 2007 Membership初体验

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

在SharePoint Server 2007中创建了site,亲手试验文档给出的Exmaple,发现运行到
UserProfileManager profileManager = new  UserProfileManager(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都是一样的结果。希望高手指点!

posted on 2006-06-30 23:42  蒜头  阅读(3746)  评论(4编辑  收藏  举报

导航