private void Validate(ListCreateQuery options) { if (options.GroupId <= 0) { throw new InvalidOperationException("The group identified is invalid."); } if (string.IsNullOrEmpty(options.SPWebUrl)) { throw new InvalidOperationException("Url cannot be empty."); } if (string.IsNullOrEmpty(options.Title)) { throw new InvalidOperationException("Title cannot be empty."); } }
public SPList Create(int templateType, ListCreateQuery options) { Validate(options); SPList list; try { using (var clientContext = new SPContext(options.SPWebUrl, credentials.Get(options.SPWebUrl))) { var site = clientContext.Site; clientContext.Load(site, s => s.Id); var listCreationInformation = new ListCreationInformation { Title = options.Title, Description = options.Description, TemplateType = templateType }; var splist = clientContext.Web.Lists.Add(listCreationInformation); clientContext.Load(splist, InstanceQuery); clientContext.ExecuteQuery(); list = new SPList(splist, site.Id) { GroupId = options.GroupId }; Add(new ListBase(list.GroupId, list.Id, options.TypeId, options.SPWebUrl) { ApplicationKey = list.Title }); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.Create() method. The exception message is: {1}", ex.GetType(), ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(list); }