We want to change some special characters from the final URL when new articles are created or updated.
For instance "Hello æøå world" would look like "Hello%20%C3%A6%C3%B8%C3%A5%20world", but we want it to instead look like "Hello-aeoa-world".
Keeping the original title is also important.
Update:
Have tried doing this:
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
SPFile file = properties.ListItem.File;
String url = file.Url.Replace(“ø”, “o”);
EventFiringEnabled = false;
if (file.Exists && !url.Equals(file.Url))
{
file.MoveTo(url, true);
file.Update();
}
EventFiringEnabled = true;
}
This will move the file properly. But since this is run after everything is complete there might not be any more updates, and the user is redirected to the old URL, which will result in a 404.
Using ItemAdding
does not help since ListItem is not created, and properties.AfterProperties does not work.
At least not any of these (testing with title):
properties.AfterProperties["Title"]= "Test";
properties.AfterProperties["Tittel"]= "Test";
properties.AfterProperties["vti_title"]= "Test";
properties.AfterProperties[SPBuiltInFields.Title.ToString()]= "Test";
And properties.BeforeUrl
and properties.AfterUrl
can not be assigned to.
If I move the file in ItemAdded
there seems to be some lost connection between properties.ListItem
and properties.ListItem.File
since the file is moved, but page layout is set to nothing (as well as content type and every other property) so it prints an error.
Update 2:
properties.AfterProperties works if I do exactly this:
public override void ItemUpdating(SPItemEventProperties properties)
{
properties.AfterProperties["vti_title"] = "test";
}
But this changes the title, not the URL. I want to change the URL and keep the title.