Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        public static string UpdateFieldWithFormula(this SPListItem item, string fieldName, string formula)
        {
            //formula = "Automated | [Company Address Line 1] - [Contract Effective Date] | [Contract Status]";

            if (!item.Fields.ContainFieldName(fieldName))
            {
                return(string.Empty);
            }

            SPField field = item.Fields[fieldName];

            string resutl = item.GetFormulaValue(formula);

            item.UpdateFieldValue(field, resutl);
            item.SystemUpdate();
            return(resutl);
        }
        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;
            }
        }