private void Bind(List <Project_Pagemap> lstPagemap, NavigationTermSetItem tsList, string root, string rootValue) { try { for (int j = 0; j < tsList.Terms.Count; j++) { if (!string.IsNullOrEmpty(tsList.Terms[j].Title.Value.ToLower())) { Project_Pagemap objPagemap = new Project_Pagemap(); objPagemap.Name = tsList.Terms[j].Title.Value; objPagemap.Subsection = root; objPagemap.TermId = tsList.Terms[j].Id; objPagemap.Url = "/" + rootValue + "/" + tsList.Terms[j].FriendlyUrlSegment.Value; lstPagemap.Add(objPagemap); if (tsList.Terms[j].Terms.Count > 0) { Bind(lstPagemap, tsList.Terms[j], tsList.Terms[j].Title.Value, rootValue + "/" + tsList.Terms[j].FriendlyUrlSegment.Value); } } } } catch (Exception ex) { lblMessage.Text = "Bind Error : " + ex.Message; } }
private void Bind(List <Project_Pagemap> dcn, NavigationTermSetItem tsList, string root, int level, int level2, string RootURl) { try { for (int j = 0; j < tsList.Terms.Count; j++) { if (!string.IsNullOrEmpty(tsList.Terms[j].Title.Value.ToLower())) { Project_Pagemap p = new Project_Pagemap(); p.Name = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(tsList.Terms[j].Title.Value.ToLower()); p.Subsection = root; p.Url = "../" + RootURl + "/" + tsList.Terms[j].FriendlyUrlSegment.Value; dcn.Add(p); if (tsList.Terms[j].Terms.Count > 0) { Bind(dcn, tsList.Terms[j], tsList.Terms[j].Title.Value, level, level2 + 1, RootURl + "/" + tsList.Terms[j].FriendlyUrlSegment.Value); } } } } catch (Exception ex) { // lblMessage.Text = "Page_Load Error : " + ex.Message; } }
/// <summary> /// Ensures that the client is requesting the current page by the associated friendly URLs (if any). /// If the client is not requesting the associated friendly URLs, the client will be transfered to the default friendly URL by a redirect response. /// </summary> /// <param name="context">The instance of the <see cref="HttpContext"/> class representing the client.</param> public static void TransferToFriendlyUrl(HttpContext context) { CommonHelper.ConfirmNotNull(context, "context"); if (SPContext.Current != null && !TaxonomyNavigationContext.Current.HasNavigationContext) { SPListItem currentItem = SPContext.Current.ListItem; if (currentItem != null) { string rawRequestPath = context.Request.RawUrl; int pathEndPos = rawRequestPath.IndexOfAny(new[] { '?', '#' }); if (pathEndPos >= 0) { rawRequestPath = rawRequestPath.Substring(0, pathEndPos); } NavigationTermSetItem matchedTerm = TaxonomyNavigation.GetFriendlyUrlsForListItem(currentItem, true).FirstOrDefault(); if (matchedTerm == null) { NavigationTermSet matchedTermSet; if (IsRequestingNavigationTermSet(out matchedTermSet)) { matchedTerm = matchedTermSet; } } if (matchedTerm != null) { string friendlyUrl = matchedTerm.GetResolvedDisplayUrl(null); if (!friendlyUrl.Equals(rawRequestPath, StringComparison.OrdinalIgnoreCase)) { if (pathEndPos >= 0) { NameValueCollection query = HttpUtility.ParseQueryString(context.Request.RawUrl.Substring(pathEndPos + 1)); query.Remove(null); query.Remove("TermStoreId"); query.Remove("TermSetId"); query.Remove("TermId"); friendlyUrl = String.Concat(friendlyUrl, "?", query.ToString()); } SPUtility.Redirect(friendlyUrl, SPRedirectFlags.Default, context); } } } } }
/// <summary> /// Adds a user-friendly URL for a PublishingPage object. /// </summary> /// <param name="page">The target page to add to managed navigation.</param> /// <param name="web">The target web.</param> /// <param name="navigationTitle">The title for the navigation item.</param> /// <param name="friendlyUrlSegment">The user-friendly text to use as the URL segment.</param> /// <param name="editableParent">The parent NavigationTermSetItem object below which this new friendly URL should be created.</param> /// <param name="showInGlobalNavigation">Defines whether the navigation item has to be shown in the Global Navigation, optional and default to true.</param> /// <param name="showInCurrentNavigation">Defines whether the navigation item has to be shown in the Current Navigation, optional and default to true.</param> /// <returns>The simple link URL just created.</returns> public static String AddNavigationFriendlyUrl(this PublishingPage page, Web web, String navigationTitle, String friendlyUrlSegment, NavigationTermSetItem editableParent, Boolean showInGlobalNavigation = true, Boolean showInCurrentNavigation = true) { // Add the Friendly URL var friendlyUrl = page.AddFriendlyUrl(friendlyUrlSegment, editableParent, true); // Retrieve terms for searching parent web.Context.Load(editableParent.Terms, ts => ts.Include(t => t.FriendlyUrlSegment, t => t.Title)); web.Context.ExecuteQueryRetry(); // Configure the friendly URL Title NavigationTerm friendlyUrlTerm = editableParent.Terms .FirstOrDefault(t => t.FriendlyUrlSegment.Value == friendlyUrlSegment); if (friendlyUrlTerm != null) { // Assign term label for taxonomy equal to navigation item title Term friendlyUrlBackingTerm = friendlyUrlTerm.GetTaxonomyTerm(); web.Context.Load(friendlyUrlBackingTerm, t => t.Labels); web.Context.ExecuteQueryRetry(); Label defaultLabel = friendlyUrlBackingTerm.Labels.FirstOrDefault(l => l.IsDefaultForLanguage); if (defaultLabel != null) { defaultLabel.Value = navigationTitle; } // Configure the navigation settings if (!showInGlobalNavigation || !showInCurrentNavigation) { if (!showInGlobalNavigation && !showInCurrentNavigation) { friendlyUrlBackingTerm.SetLocalCustomProperty("_Sys_Nav_ExcludedProviders", "\"GlobalNavigationTaxonomyProvider\",\"CurrentNavigationTaxonomyProvider\""); } if (!showInGlobalNavigation) { friendlyUrlBackingTerm.SetLocalCustomProperty("_Sys_Nav_ExcludedProviders", "\"GlobalNavigationTaxonomyProvider\""); } else { friendlyUrlBackingTerm.SetLocalCustomProperty("_Sys_Nav_ExcludedProviders", "\"CurrentNavigationTaxonomyProvider\""); } } // Assign term title for site navigation friendlyUrlTerm.Title.Value = navigationTitle; friendlyUrlTerm.GetTaxonomyTermStore().CommitAll(); web.Context.ExecuteQueryRetry(); } return (friendlyUrl.Value); }
public TaxonomyNavigationRequestContext() { this.context = TaxonomyNavigationContext.Current; this.variation = VariationContext.Current; if (context.HasNavigationContext) { this.navigationTerm = context.NavigationTerm; } else { using (new SPSecurity.GrantAdditionalPermissionsInScope(SPBasePermissions.FullMask)) { SPWeb currentWeb = SPContext.Current.Web; string url = TaxonomyNavigationHelper.ResolveFriendlyUrl(currentWeb, SPUrlUtility.CombineUrl(currentWeb.ServerRelativeUrl, currentWeb.RootFolder.WelcomePage)); TaxonomyNavigationHelper.TryGetNavigationTerm(url, out this.navigationTerm, out url); } } if (this.navigationTerm == null) { NavigationTermSet termSet; TaxonomyNavigationHelper.IsRequestingNavigationTermSet(out termSet); this.navigationTermSetItem = termSet; } else { this.navigationTermSetItem = navigationTerm; } if (context.HasFriendlyUrl || context.HasCatalogUrl) { this.serverRelativeRequestUrl = context.ResolvedDisplayUrl; } else if (navigationTermSetItem != null) { this.serverRelativeRequestUrl = navigationTermSetItem.GetResolvedDisplayUrl(null); } else { this.serverRelativeRequestUrl = SPUtility.OriginalServerRelativeRequestPath; } this.variationRelativeRequestUrl = PublishingWebHelper.TrimVariationFromPath(serverRelativeRequestUrl); this.query = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query); query.Remove(null); query.Remove("TermStoreId"); query.Remove("TermSetId"); query.Remove("TermId"); this.queryString = query.AllKeys.Length > 0 ? "?" + query : String.Empty; SPListItem listItem = SPContext.Current.ListItem; if (listItem != null) { this.currentItem = SPModel.TryCreate(listItem); } if (currentItem is ICatalogPage) { ICatalogPageFilter filter = CommonHelper.AccessNotNull(((ICatalogPage)currentItem).Filter, "Filter"); SetCatalogPageFilter(filter); } if (currentItem is ISeoMetaProvider) { seoMeta.Add((ISeoMetaProvider)currentItem); } seoMeta.Add(new SeoMetaListItem(listItem)); for (NavigationTerm t = navigationTerm; t != null; t = t.Parent) { seoMeta.Add(new SeoMetaNavigationTerm(listItem.Web, t)); } }