sharepoint 2013 CSOM将termset设为'navigation termset',最后一行代码抛出异常

时间:2014-06-19 02:21:30

标签: sharepoint csom

Guid termSetGUID = new Guid("7ab9e8b0-e1e1-4a7c-9b20-d6c5030103df");

string siteUrl = "http://win-f33ohjutmmi/sites/cms";
ClientContext clientContext = new ClientContext(siteUrl);

TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
taxonomySession.UpdateCache();

clientContext.Load(taxonomySession, ts => ts.TermStores);
clientContext.ExecuteQuery();

if (taxonomySession.TermStores.Count == 0)
     throw new InvalidOperationException("The Taxonomy Service is offline or missing");

TermStore termStore = taxonomySession.TermStores[0];
clientContext.Load(termStore,
        ts => ts.Name,
        ts => ts.WorkingLanguage);
clientContext.ExecuteQuery();

// Does the TermSet object already exist?
TermSet existingTermSet;
TermGroup siteCollectionGroup;

siteCollectionGroup = termStore.GetSiteCollectionGroup(clientContext.Site,createIfMissing: true);

existingTermSet = termStore.GetTermSet(termSetGUID);
clientContext.Load(existingTermSet);
clientContext.ExecuteQuery();
if (!existingTermSet.ServerObjectIsNull.Value)
{
     existingTermSet.DeleteObject();
     termStore.CommitAll();
     clientContext.ExecuteQuery();
}

TermSet termSet = siteCollectionGroup.CreateTermSet("CMSNavigationTermSet", termSetGUID,termStore.WorkingLanguage);

termStore.CommitAll();
clientContext.ExecuteQuery();

NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(clientContext,termSet, clientContext.Web, "GlobalNavigationTaxonomyProvider");

navTermSet.IsNavigationTermSet = true;

termStore.CommitAll();
clientContext.ExecuteQuery();//THIS line always throw exception "The object is in invalid state"

大多数代码运行良好,TermSets被创建,但当我尝试将此TermSet作为导航TermSet时,最后一个ExecuteQuery抛出异常。

1 个答案:

答案 0 :(得分:1)

尝试以下代码。它工作正常。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [FBSDKLoginButton class];
    return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}

    - (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url                                              sourceApplication:sourceApplication                                                     annotation:annotation];
}