12

I usually work with sharepoint on-premises 2013, and when i work with enterprise wiki site collection, i write the following server side event receiver, which mainly update the friendly URL term to match the updated wiki page name. as by defualt if i create a new wiki page named "test 123", then its friendly url will be "test-123". but if i modify the wiki page name for example to be equal to "test 123 updated name".. then this new name will not be reflected inside the friendly url term. so when i am inside on-premises i write the following ItemUpdated event receiver, to update the friendly url to match the new wiki page name :-

public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
//code goes here
// main code is
 SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(properties.SiteId))
                        {
                            string currenweburl = properties.RelativeWebUrl;
                            using (SPWeb spCurrentSite = site.OpenWeb(currenweburl))
                            {

                                Term currenttermset = null;
                                TaxonomySession txSession = new TaxonomySession(site);
                                TermStore tc = txSession.TermStores[termstorename.Trim()];
                                Group g = tc.Groups[groupname.Trim()];
                                TermSet ts = g.TermSets[termsetname.Trim()];
                                foreach (Term t56 in ts.Terms)
                                {
                                    string targetPageURL = "";
                                    if (t56.LocalCustomProperties.Keys.Contains("_Sys_Nav_TargetUrl"))
                                    {
                                        targetPageURL = t56.LocalCustomProperties["_Sys_Nav_TargetUrl"];//.Replace("%5B", "[");
                                    }
                                    // string targetPageURL = t56.LocalCustomProperties["_Sys_Nav_TargetUrl"];//.Replace("%5B", "[");
                                    //  targetPageURL = targetPageURL.Replace("%5D", "]");
                                    if (targetPageURL.ToString().ToLower().Trim().Contains(properties.ListItem.Name.ToLower().Trim()))
                                    {
                                        currenttermset = t56;
                                        break;
                                    }
                                }
                                if (currenttermset != null && currenttermset.Id != null)
                                {
                                    string modifieddisplayname = properties.ListItem.DisplayName.Replace(";", "");// since the ; is the only charecters which is allowed inside the Name but not insdie the term. so if the name contain ; an eror will be raised when i try to add the term
                                    modifieddisplayname = System.Text.RegularExpressions.Regex.Replace(modifieddisplayname, @"\s+", " ");//i did so since if the name contain two white spaces or more it will be added as single white space inside the term
                                    string modifeidtemr = System.Text.RegularExpressions.Regex.Replace(currenttermset.Name, @"\s+", " ");
                                    if (!String.IsNullOrEmpty(properties.ListItem["Title"].ToString())
                                        && (modifeidtemr.Trim() != modifieddisplayname.Trim()))
                                    {
                                        string modifieddisplayname2 = properties.ListItem.DisplayName.Replace(";", "");
                                        currenttermset.Name = modifieddisplayname2;

                                        tc.CommitAll();
                                        SPListItem newlogentry = xlogs.AddItem();
                                        newlogentry["Title"] = "Term= " + modifieddisplayname2;
                                        newlogentry.Update();



                                    }

                                }
                            }
                        }
                    });

in short the above event receiver will do the following main operations:-

  1. loop through the related navigation term.
  2. get the term which have its target page = the updated wiki page.
  3. check if the term equal to the wiki page name. (i have to replace ; with empty space) since i can have ; inside the name while this character will be automatically removed from the term name.
  4. now if the page name is not equal to the term name. i will updated the term accordingly..

now i know that inside office 365 world i can not write server-side event receivers, and at this stage i am afraid i do not have the required knowledge and experience to write the above as remote event receiver. so my question is whether i can use workflow 2013 to be able to update the friendly url term to match the new wiki page name?? Thanks

  • 2
    Another option can be using powershell script which will check it periodically and fix it using CSOM. – Petr Štěpka Aug 10 '17 at 19:44
  • @PetrŠtěpka looks promising ... but can you post sample code ? please? – john Gu Aug 14 '17 at 1:35
0

Have you tried using the HTTP request activity and using the REST api to do this task ?

I use it to update lists sometimes when working with workflows built in SharePoint Designer.

The specifics on how to update list items or library items can be found here

I don't know if event receivers run in a sandbox solution, I just know that running in sandbox mode you cannot make a HTTP call.

You could create a workflow that takes a parameter and updates the appropriate field using that and the instructions found here on how to configure a HTTP request

0

The managed navigation feature in SharePoint Server enables you to build navigation for a publishing site that is derived from a SharePoint Server managed metadata taxonomy.

In SharePoint Server 2010, by default, you could base navigation only on the structure of a site. To create site navigation based on any data structure, you had to create a custom navigation provider.

By using managed navigation, you can design site navigation around important business concepts. Managed navigation also lets you login into your router easily and create friendly URLs without changing the structure of your site.

In SharePoint Server 2010, all publishing site URLs contained a reference to the Pages library and any folders within that library.

For example: http://contoso.com/Pages/AboutUs.aspx.

In SharePoint Server 2016 and SharePoint Server 2013, you can create URLs that are better for Search Engine Optimization (SEO), and easier for site visitors to read.

For example:

http://contoso.com/AboutUs.

Managed navigation is not available in SharePoint Foundation 2013.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.