Linking content items with ContentLinksManager
Hi,
I've some troubles setting up ContentLinks between a custom module (Group) and an Image. I was able to set up a proper link between them using this code:
var groupLive = manager.GetGroups().Where(x => x.Username ==
this
.emailAddress.Text && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).FirstOrDefault();
var imageLive = librariesManager.GetImages().Where(x => x.Title == imageName && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).FirstOrDefault();
var contentLinkManager = ContentLinksManager.GetManager();
var link = contentLinkManager.GetContentLink(groupLive.Id,
typeof
(Group),
"GroupImage"
);
if
(link ==
null
)
link = contentLinkManager.CreateContentLink(
"GroupImage"
, groupLive, imageLive);
else
link.ChildItemId = image.Id;
contentLinkManager.SaveChanges();
Hello Daniel,
How exactly do you publish the created item? If you are using mng.Publish, your Publish method should be returning the live item and after that it would be very easy to get its ID and use it to create the ContentLink.
All the best,Hi Svetoslav,
I use this code to publish an item, since other options didn't work for me. Maybe you can show me the right code to checkout, checkin and publish an item?
// Save changes to the database
group = manager.Lifecycle.CheckIn(temp)
as
GroupItem;
manager.RecompileItemUrls(group);
manager.SaveChanges();
//Publish the news item.
var bag =
new
Dictionary<
string
,
string
>();
bag.Add(
"ContentType"
,
typeof
(GroupItem).FullName);
WorkflowManager.MessageWorkflow(group.Id,
typeof
(GroupItem),
null
,
"Publish"
,
false
, bag);
manager.Provider.SuppressSecurityChecks =
false
;
So, when I use this manager.LifeCycle.Publish, I get a ILifeCycleDataItem back.
What would be the best way to create a content link between an image and a group based on two ID's?
I tried this code but it gives an error that it cannot find the 'GroupItem' type:
link = contentLinkManager.CreateContentLink(
"GroupImage"
,
groupId, image.Id, GroupsManager.GetDefaultProviderName(), librariesManager.Provider.Name,
typeof
(GroupItem).Name,
typeof
(Telerik.Sitefinity.Libraries.Model.Image).Name);
Hi Daniel,
Here's how you can do the publish:
group.ApprovalWorkflowState =
"Published"
;
var live = manager.Lifecycle.Publish(master);
manager.SaveChanges();
var groupItem = live
as
GroupItem