Benutzer:MovGP0/70-489/MMS

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Implement Managed Metadata Service (MMS)

[Bearbeiten | Quelltext bearbeiten]

Manage Term Sets

[Bearbeiten | Quelltext bearbeiten]

Term übersetzen

[Bearbeiten | Quelltext bearbeiten]
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using System.Globalization;

using(var site = new SPSite("http://.../"))
{
   var taxonomySession = new TaxonomySession(site);
   var term = taxonomySession.GetTerms("TermSetName", false).SingleOrDefault();

   if(term == null) return;

   var french = CultureInfo.CreateSpecificCulture("fr-fr");
   
   term.CreateLabel("Au Revoir", french, false);
   term.TermStore.CommitAll();
}

Term wiederverwenden

[Bearbeiten | Quelltext bearbeiten]
using(var site = new SPSite("http://.../"))
{
   var taxonomySession = new TaxonomySession(site);
   var sourceTermSet = taxonomySession.GetTerms("SourceTermSetName", false).SingleOrDefault();
   if(sourceTermSet == null) return;

   var targetTermSet = taxonomySession.GetTerms("TargetTermSetName", false).SingleOrDefault();
   if(targetTermSet == null) return;

   var termToReuse = sourceTermSet.GetTerms("TermName", false).SingleOrDefault();
   if(termToReuse  == null) return;

   targetTermSet.ResuseTerm(termToReuse, false);
   targetTermSet.TermStore.CommitAll();
}

Term-Einstellungen setzen

[Bearbeiten | Quelltext bearbeiten]
using(var site = new SPSite("http://..."))
{
   var taxonomySession = new TaxonomySession(site);
   var term = taxonomySession.GetTerms("TermName", false).SingleOrDefault();
   if(term == null) return;

   var english = CultureInfo.CreateSpecificCulture("en-US");
   term.SetDescription("Some description", english.LCID);
   term.SetCustomProperty("My Property", "My Value");
   term.TermStore.CommitAll();
}

Groups and Permissions

[Bearbeiten | Quelltext bearbeiten]
using(var site = new SPSite("http://..."))
{
   var taxonomySession = new TaxonomySession(site);
   var termStore = taxonomySession.TermStores["Managed Metadata Service"]; // "Managed Metadata Service" is the default store
   
   // create group and assign permissions
   var termGroup = termStore.CreateGroup("Custom Group");
   termGroup.AddGroupManager(@"dev\Administrator");
   termGroup.AddContributor(@"dev\User");
   termGroup.CommitAll();
}

Create Solutions using MMS

[Bearbeiten | Quelltext bearbeiten]

Implement Metadata-Driven Navigation[1]

[Bearbeiten | Quelltext bearbeiten]
using(var site = new SPSite("http://sharepoint/sites/mms"))
{
   var taxyonomySession = new TaxonomySession(site);

   var termStore = taxonomySession.TermStores["Managed Metadata Service"];
   var termGroup = termStore.Groups.Where(g => g.Name = "Global");
   if(termGroup == null) return;

   var termSet = termGroup.CreateTermSet("Navigation", Guid.NewGuid())
   var navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, site.AllWebs[0], StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);
   navTermSet.IsNavigationTermSet = true;
   navTermSet.TargetUrlForChildTerms.Value = "/sites/mms/_layouts/15/start.aspx";

   var term1 = navTermSet.CreateTerm("Page 1", NavigationLinkType.SimpleLink); 
   term1.SimpleLinkUrl = "/sites/mms/SitePages/Page1.aspx";

   var term2 = navTermSet.CreateTerm("Page 1", NavigationLinkType.SimpleLink);
   term1.SimpleLinkUrl = "/sites/mms/SitePages/Page2.aspx";

   termStore.CommitAll();

   // Create a WebNavigationSettings object to set the global nav on our site
   var webNavSettings = new WebNavigationSettings(site.AllWebs[0]) {
      GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider, 
      AddNewPagesToNavigation = false, 
      CreateFriendlyUrlsForNewPages = false, 
      GlobalNavigation.TermStoreId = termStore.Id, 
      GlobalNavigation.TermSetId = termSet.Id
   };
   webNavSettings.Update(taxonomySession);
}

Use the Product Catalog and Cross-Site Publishing[2]

[Bearbeiten | Quelltext bearbeiten]
  • Create new site
  • Publishing → Product Catalog
  • Populate Site CollectionProduct Hierarchy with terms
  • Configure cross-site publishing by declaring list as a catalog
    • List SettingsCatalog SettingsCatalog SharingEnable this libary as a catalog
  • Configure Site Collections that should have access to the catalog
    • Site SettingsSite AdministrationTerm store managementSite CollectionSite Collection Access
    • Add URLs to site (one per line; ie. http://sharepoint/sites/mms)
  • Configure target site to use the catalog
    • Navigate to target site
    • Site SettingsSite AdministrationManage catalog connections
    • Connect a catalog → select catalog → Connect
    • Select column to use in Navigation Hierarchy

Using CSOM and SSOM

[Bearbeiten | Quelltext bearbeiten]
create Managed Metadata Terms
Client-Side Object Model (CSOM) Server-Side Object Model (SSOM)
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;

var english = CultureInfo.CreateSpecificCulture("en-US");

using(var context = new ClientContext("http://sharepoint/sites/mms"))
{
   var taxonomySession = TaxonomySession.GetTaxonomySession(context);

   var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
   context.Load(termStore)
   var termSet = termStore.GetTermSet(new Guid("...."));
   var termCollection = termSet.GetAllTerms();
   context.Load(termCollection, s => s.Include(t => t.Name));
   context.ExecuteQuery();

   var term1 = termSet.CreateTerm("Term 1", english.LCID, Guid.NewGuid());
   term1.IsAvailableForTagging = true;

   var term2 = termSet.CreateTerm("Term 2", english.LCID, Guid.NewGuid());
   term1.IsAvailableForTagging = true;

   context.ExecuteQuery();

   var parentTerm = termColelction.SingleOrDefault(x => x.Name = "Term 1");
   var childTerm = parentTerm.CreateTerm("Child 1-1", english.LCID, Guid.NewGuid());
   childTerm.IsAvailableForTagging = true;

   context.ExecuteQuery();

   context.Load(termCollection, s => s.Include(x => x.Name), s => s.Include(x => x.TermSet.Name));
   context.ExecuteQuery();
   foreach(var term in termCollection)
   {
       Console.WriteLine(string.Format("Term Set: {0}, Term: {1}", term.TermSet.Name, term.Name);
   }
}
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;

var english = CultureInfo.CreateSpecificCulture("en-US");

using(var site = new SPSite("http://sharepoint/sites/mms"))
{
   var taxonomySession = new TaxonomySession(site);
   
   var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
   context.Load(termStore)
   var termSet = termStore.GetTermSet(new Guid("...."));
   var termCollection = termSet.GetAllTerms();
   context.Load(termCollection, s => s.Include(t => t.Name));
   context.ExecuteQuery();

   var term1 = termSet.CreateTerm("Term 1", english.LCID, Guid.NewGuid());
   term1.IsAvailableForTagging = true;

   var term2 = termSet.CreateTerm("Term 2", english.LCID, Guid.NewGuid());
   term1.IsAvailableForTagging = true;

   context.ExecuteQuery();

   var parentTerm = termColelction.SingleOrDefault(x => x.Name = "Term 1");
   var childTerm = parentTerm.CreateTerm("Child 1-1", english.LCID, Guid.NewGuid());
   childTerm.IsAvailableForTagging = true;
   
   termStore.CommitAll();
   
   var termSetAfterCommit = termStore.GetTermSet(new Guid("..."));
   foreach(var term in termSetAfterCommit)
   {
      Console.WriteLine(string.Format("Term Set: {0}, Term: {1}", term.TermSet.Name, term.Name));
      if(term.Terms.Count > 0)
      {
         foreach(var childTerm in term.Terms)
         {
            Console.WriteLine(string.Format("   Term Set: {0}, Term: {1}", childTerm.TermSet.Name, childTerm.Name));
         }
      }
   }
}

Use REST in Client Applications

[Bearbeiten | Quelltext bearbeiten]

Use Managed Fields

[Bearbeiten | Quelltext bearbeiten]
using(var site = new SPSite("http://sharepoint/sites/mms"))
{
   // get term set
   var taxonomySession = new TaxonomySession(site);
   var termSet = taxonomySession.GetTermSets("TermSetName").Single();
   
   // create field
   var field = site.RootWeb.Fields.CreateNewField("TaxonomyFieldType", "Custom Field") as TaxonomyField;
   field.SspId = termSet.TermStore.Id;
   field.TermSetId = termSet.Id;
   field.TargetTemplate = string.Empty;
   field.AllowMultipleValues = true;

   // add field to site
   site.RootWeb.Fields.Add(field);
   site.RootWeb.Update();
   
   // add field to list
   var fieldAdded = site.RootWeb.Fields["Custom Field"] as TaxonomyField;
   var list = site.RootWeb.Lists["Custom List"];
   list.Fields.Add(fieldAdded);
   list.Update();
}
  1. SP.Publishing.Navigation namespace (sp.publishing). In: MSDN. Microsoft, abgerufen am 14. Mai 2014.
  2. Cross-site publishing in SharePoint 2013. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 14. Mai 2014 (englisch).