예제 #1
0
        private void CreateList(SPListItem listItem, SPWeb web, ListIntanceDefinition definition, string UrlFieldName, out string listUrl)
        {
            listUrl = string.Empty;
            try
            {
                var template = web.ListTemplates.Cast <SPListTemplate>().Where(p => p.Name == definition.TemplateName).FirstOrDefault();
                if (template == null)
                {
                    return;
                }
                string title = listItem.GetFormulaValue(definition.Title);
                string url   = listItem.GetFormulaValue(definition.Url).Simplyfied();
                if (template.CategoryType == SPListCategoryType.CustomLists)
                {
                    url = "Lists/" + url;
                }

                var listId = web.Lists.Add(title, string.Empty, url, template.FeatureId.ToString(), template.Type_Client, "100", SPListTemplate.QuickLaunchOptions.Default);
                // Guid listId = web.Lists.Add(item.Title, item.Description, item.Url, template.FeatureId.ToString(), item.TemplateId, "100");

                SPList list = web.Lists[listId];
                list.ContentTypesEnabled = true;
                list.EnableVersioning    = true;
                list.EnableModeration    = true; //enable Content Approval
                foreach (var item in definition.ContentTypes)
                {
                    list.EnsureContentTypeInList(item);
                }

                var urlValue = new SPFieldUrlValue();
                urlValue.Description = title;
                urlValue.Url         = web.Url + "/" + url;

                using (DisableItemEvent disableItemEvent = new DisableItemEvent())
                {
                    listItem[UrlFieldName] = urlValue;
                    listItem.Update();
                }


                listUrl = urlValue.Url;
                list.Update();
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message + ex.StackTrace, AIAPortalFeatures.Infrastructure);
                //throw;
            }
        }