Skip to content

Instantly share code, notes, and snippets.

@davidknipe
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidknipe/ee774990d969a0b78258 to your computer and use it in GitHub Desktop.
Save davidknipe/ee774990d969a0b78258 to your computer and use it in GitHub Desktop.
Adding items to an EPiServer Project
/// <summary>
/// Add items to a project
/// </summary>
/// <param name="repo">The ProjectRepository instance</param>
/// <param name="project">The project to save the items against</param>
/// <param name="contentReferences">A list of ContentReferences to add to the project. *Note!* the item to add should be the draft version number, not the current published version number</param>
/// <returns>A list of the saved project items</returns>
public IList<ProjectItem> AddItemsToProject(ProjectRepository repo, Project project,
IList<ContentReference> contentReferences)
{
// Set up a list of Project Items to add.
var projectItems = new List<ProjectItem>();
contentReferences.ForEach(x => projectItems.Add(
new ProjectItem()
{
ContentLink = x,
ProjectID = project.ID,
Category = "content",
Language = new CultureInfo("en") // Ensure correct language is selected based on contentReference
}));
//Save the items to the project
repo.SaveItems(projectItems);
return projectItems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment