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/4f53125af30a1805c868 to your computer and use it in GitHub Desktop.
Save davidknipe/4f53125af30a1805c868 to your computer and use it in GitHub Desktop.
Create an EPiServer Project programmatically
/// <summary>
/// Create a project programmatically
/// </summary>
/// <param name="projectName">The name of the project, e.g. "Weekly article updates"</param>
/// <param name="userName">The username of the person creating the project</param>
/// <returns>The newly created project, null if a project with that name already exists</returns>
public Project CreateNewProject(string projectName, string userName)
{
var repo = ServiceLocator.Current.GetInstance<ProjectRepository>();
var newProject = new Project();
if (repo.List().Any(x => x.Name == projectName) == false)
{
newProject.Name = projectName;
newProject.CreatedBy = userName;
repo.Save(newProject);
return newProject;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment