Last active
August 29, 2015 14:22
-
-
Save davidknipe/ee774990d969a0b78258 to your computer and use it in GitHub Desktop.
Adding items to an EPiServer Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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