Create, Delete & Modify Items

Fortis not only allows you to read items from Sitecore but also manage them with the strongly typed objects. The following examples show how you can create, modify, delete and publish items.

Create

public class MyProvider
{
	private readonly IItemFactory _itemFactory;

	public MyProvider(IItemFactory itemFactory)
	{
		_itemFactory = itemFactory;
	}

	private void Run()
	{
		IPage item = _itemFactory.Create<IPage>(/* Guid or path */, "Item Name");
	}
}

Modify

IPage item = _itemFactory.GetContextItem<IPage>();

item.Title.RawValue = "Amended Title";
item.Save();

Delete

IItemWrapper item = _itemFactory.GetContextItem<IItemWrapper>();

item.Delete();

Publish – Single Item

IItemWrapper item = _itemFactory.GetContextItem<IItemWrapper>();

item.Publish();

Publish – Multiple Items

IItemWrapper item = _itemFactory.GetContextItem<IItemWrapper>();
IEnumerable<IItemWrapper> children = item.Children<IItemWrapper>();

_itemFactory.Publish(children);

Next: Rendering Parameters