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:-
- loop through the related navigation term.
- get the term which have its target page = the updated wiki page.
- 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.
- 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