Friday 4 November 2016

SharePoint - Programmatically get Friendly URL of Publishing pages

Hi Guys - After so long time, I am posting this. I got so busy in my project. Finally I am getting some time to post this. I got his requirement of finding the Friendly URL of Publishing pages.

Code is given below. Hope this helps someone.



using (SPSite osite = new SPSite("site url"))
            {
                using (SPWeb oweb = osite.OpenWeb())
                {
                    SPList olist = oweb.Lists["Pages"];
                    foreach (SPListItem item in olist.Items)
                    {
                        var associatedTerms = TaxonomyNavigation.GetFriendlyUrlsForListItem(item, false);

                        string url = string.Empty;
                        if (associatedTerms.Count > 0)
                        {
                            url = associatedTerms[0].GetResolvedDisplayUrl(string.Empty);
                        }
                    }
                }
            }


Happy Coding :)

No comments:

Post a Comment