Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Get Top Leve Site URL

$
0
0

I have a SharePoint 2013 Publishing face site with an AAM as the following

Default:   http://www.abc.com

Internet:  http://abc.com

I have a custom webpart that work with term sets for site navigation.  I used the spcontext.current.site.url.tostring() to get the dynamic top level url. However, it seems does not work. The site already live in a DMZ zoon can I am not able do debugging. Please see the lines the have green background. I really appreciate if someone can point it out what is my problem or give me a better approach. Many thanks

       protectedvoid Page_Load(object sender, EventArgs e)

       {           

           // string to_page_level = HttpContext.Current.Request.Url.AbsolutePath;

           csURL = SPContext.Current.Site.Url.ToString()+ "/";  

           string to_page_level =HttpContext.Current.Request.RawUrl;

           string[] splits = to_page_level.Split('/');

           renderTaxonomyServerObject(splits[1], to_page_level);

           //           navigationHTML.Text += "<BR/>" + to_page_level + "<B><BR/>" + splits[0] + ";" + splits[1] + ";" + splits[2] + "</B>";

       }

       

       privatevoid renderTaxonomyServerObject(string root_level, string to_page_level)

       {

           SPSecurity.RunWithElevatedPrivileges(delegate()

           {

               //SPSite site = new SPSite("http://www.abc.com/");

               SPSite site =newSPSite(csURL);

               TaxonomySession taxonomySession =newTaxonomySession(site);

               navigationHTML.Text = "<table name='termnavigation' style='width: 213px' cellspacing='0' cellpadding='0'>";

               if (taxonomySession !=null&& taxonomySession.TermStores.Count > 0)

               {

                   TermStore termStore = taxonomySession.TermStores[0];

                   for (int i = 0; i < termStore.Groups.Count; i++)

                   {

                       Microsoft.SharePoint.Taxonomy.Group termGroup = termStore.Groups[i];

                   }

                   foreach (Microsoft.SharePoint.Taxonomy.Group termGroup in termStore.Groups)

                   {

                       foreach (Microsoft.SharePoint.Taxonomy.TermSet termSet in termGroup.TermSets)

                       {

                           //                           navigationHTML.Text += "<B> " + termStore.Name + "|" + termGroup.Name + "|" + termSet.Name + " [" + termSet.Terms.Count + "]</B></BR>";

                           if (string.Compare(termSet.Name,"cambaNavigation",true) == 0)// we are only concerned with camba navigation

                           {

                               foreach (Microsoft.SharePoint.Taxonomy.Term term in termSet.Terms)

                               {

                                   //                                   string termName = term.Name;

                                   if (string.Compare(term.Name, root_level.Trim(), true) == 0)// but we dont want to actually show the root level node since we

                                   {                                                    // have those in the upper navigation so lets loop thru its children

                                       foreach (Microsoft.SharePoint.Taxonomy.Term rootTermsin term.Terms)

                                       {

                                           //recursiveServerTermStoreFetch(rootTerms, 0, "http://www.abc.com/"+ root_level.ToLower().Replace(" ", ""), to_page_level, false);

                                           recursiveServerTermStoreFetch(rootTerms, 0, csURL + root_level.ToLower().Replace(" ",""), to_page_level,false);

                                       }

                                   }

                               }

                           }

                       }

                   }

               }

               navigationHTML.Text += "</table>";

           });

       }

   }

}


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>