Skip to content

Instantly share code, notes, and snippets.

@merkle-sitecore-gists
Last active February 27, 2019 16:45
Show Gist options
  • Save merkle-sitecore-gists/f9d320600de59b562ca26666863300a0 to your computer and use it in GitHub Desktop.
Save merkle-sitecore-gists/f9d320600de59b562ca26666863300a0 to your computer and use it in GitHub Desktop.
Bugfix for Sitecore 9 SocialConnect module creating items with an invalid name
...
protected void SavePostMessage(string network, string NewtworkPagename, string postid, string pageid, ....)
{
try
{
using (SecurityDisabler securityDisabler = new SecurityDisabler())
{
Database database = Factory.GetDatabase("master");
Item item = database.GetItem("/sitecore/system/Social/PostMessage");
TemplateItem template = database.GetTemplate(SocialTemplates.SocialMessages.ID);
DateTime utcNow = DateTime.UtcNow;
string itemname = string.Concat(network, utcNow.ToString().Replace("/", "").Replace("\\", "").Replace(" ", "-").Replace(":", ""), "-", pagename);
itemname = itemname.Replace("\\", "").Replace("/", "").Replace(":", "").Replace("<", "").Replace(">", "").Replace("[", "").Replace("]", "");
itemname = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(itemname); // new line of code, create a valid item name for the Sitecore-item.
...
protected void SavePostMessageWithShedule(string network, string NewtworkPagename, string postid, string pageid, ....)
{
...
itemname = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(itemname); // new line of code, create a valid item name for the Sitecore-item.
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment