2011-07-25 4 views
1

http://msdn.microsoft.com/en-us/library/ms545122.aspxのようにMicrosoftコードを使用してUser Profile Serverで新しい組織を作成しています。CreateOrganizationProfileエラーオブジェクト参照がオブジェクトのインスタンスに設定されていません

私は次の取得CreateOrganizationProfileを呼び出すたびに:

System.NullReferenceException: Object reference not set to an instance of an object. 
    at Microsoft.Office.Server.UserProfiles.OrganizationProfile.set_Parent(ProfileBase value) 

私が使用している正確なコードは次のとおりです。

[WebMethod] 
    public void CreateOrganisation(string OrganisationName) 
    { 
     SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 
      using (SPSite site = new SPSite(_serverName)) 
      { 
       // Removing this will cause the error "Operation is not valid due to the current state of the object". 
       HttpContext.Current = null; 

       SPServiceContext context = SPServiceContext.GetContext(site); 

       ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context); 

       // choose default organization profile subtype as the subtype 
       string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization); 
       ProfileSubtype subType = psm.GetProfileSubtype(subtypeName); 

       OrganizationProfileManager opm = new OrganizationProfileManager(context); 

       // choose Root Organization as the parent 
       OrganizationProfile parentOrg = opm.RootOrganization; 

       // create an organization profile and set its display name 
       OrganizationProfile profile = opm.CreateOrganizationProfile(subType, parentOrg); 
       profile.DisplayName = "Test Org1"; 

       // commit to save changes 
       profile.Commit(); 

      } 
     }); 

     return; 
    } 

不思議なことに、他の誰かがhttp://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/7b5101fd-0ea6-4716-82b1-ac4609b9973c/ここで正確な問題に遭遇しましたしかし決して解決されませんでした。

私は、User Profile Serviceが動作しており、応答していることを確認しました。また、CreateOrganizationProfileを呼び出すとき、parentOrgとsubtypeNameはnullではありません。

誰かが私が試すことができるものはありますか?

非常に感謝します!

+0

私は同じ問題に直面しています。私は同じ問題に直面しています –

答えて

1

私はSharePointの専門家午前ませんが、ユーザープロファイルの管理者権限が必要です。このhttp://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.organizationprofilemanager.createorganizationprofile.aspx状態とこのhttp://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.organizationprofile.parent.aspxはあなたがやろうとしている何をすべきか、ユーザー・プロファイル・マネージャーの許可が必要であることを暗示することができます。

EDIT:
あなたのコードは、これが関連すると思われるものを「書く」しようとするので、http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
基本的に、それはあなたが、私は同じ問題を抱えていたと私は固定

+0

ヤヒア - あなたが何かに就いているかもしれないと思います...私は調査し、報告します!あなたの答えをありがとう - それが正しい場合は、私はあなたにビールを借りているよ!他の提案はまだ歓迎されています! – ben

1

SPSecurity.RunWithElevatedPrivilegesを呼び出す前にSPUtility.ValidateFormDigest()またはSPWeb.ValidateFormDigest()への呼び出しが欠落していると言いますそれ

OrganizationProfile parentOrg = (OrganizationProfile)opm.GetProfile(1); 
012にライン

OrganizationProfile parentOrg = opm.RootOrganization; 

を変化させることにより、

私の場合、GetProfile(1)がRootOrganizationを返しました。

これが誰かを助けることを願っています!

関連する問題