예제 #1
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb  currentWeb  = properties.Feature.Parent as SPWeb;
            SPList classesList = currentWeb.Lists["Classes"];

            SPField titleField = classesList.Fields["Title"];

            titleField.Required       = false;
            titleField.ShowInNewForm  = false;
            titleField.ShowInEditForm = false;
            titleField.Title          = "Class ID";
            titleField.Update();

            SPField registrationsField = classesList.Fields["Registrations"];

            registrationsField.DefaultValue  = "0";
            registrationsField.ShowInNewForm = false;
            registrationsField.Update();

            SPFieldDateTime startDate = currentWeb.Fields["Start Date"] as SPFieldDateTime;

            startDate.DisplayFormat = SPDateTimeFieldFormatType.DateTime;
            SPFieldDateTime endDate = currentWeb.Fields["End Date"] as SPFieldDateTime;

            endDate.DisplayFormat = SPDateTimeFieldFormatType.DateTime;
            classesList.Fields.Add(startDate);
            classesList.Fields.Add(endDate);
            SPView defaultView = classesList.DefaultView;

            defaultView.ViewFields.Add(startDate);
            defaultView.ViewFields.Add(endDate);
            defaultView.Update();
            classesList.Update();
        }
예제 #2
0
        public SPView Create(SPList list)
        {
            SPView view = list.GetView(Name);
            IEnumerable <SPField> viewFields = GetViewFields(list);

            if (view == null)
            {
                StringCollection strViewFields = new StringCollection();
                strViewFields.AddRange(viewFields.Select(vf => vf.InternalName).ToArray());
                view = list.Views.Add(Name, strViewFields, Query, RowLimit, Paged, IsDefault, ViewType, IsPersonal);
            }
            else
            {
                view.ViewFields.DeleteAll();

                foreach (SPField viewField in viewFields)
                {
                    view.ViewFields.Add(viewField);
                }

                view.Hidden      = Hidden;
                view.Scope       = Scope;
                view.Query       = Query;
                view.RowLimit    = RowLimit;
                view.Paged       = Paged;
                view.DefaultView = IsDefault;
                view.Update();
            }

            return(view);
        }
        public static SPView UpdateDefaultView(this SPList list, string ViewName, List <string> SortedViewFields)
        {
            try
            {
                SPView view = null;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    list.ParentWeb.AllowUnsafeUpdates = true;

                    // get the view instance by view display name
                    view = list.Views[ViewName];

                    //Delete all existing fields
                    view.ViewFields.DeleteAll();

                    // add fields to the view
                    foreach (var field in SortedViewFields)
                    {
                        view.ViewFields.Add(field);
                    }

                    // update view for new fields
                    view.Update();
                    list.Update();
                });
                return(view);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(null);
            }
        }
예제 #4
0
        static SPList CreateSupplierList(SPWeb web)
        {
            SPList list = CreateList(web, "Suppliers");

            list.Fields.Add("CompanyName", SPFieldType.Text, true);
            list.Fields.Add("ContactName", SPFieldType.Text, false);
            list.Fields.Add("ContactTitle", SPFieldType.Text, false);
            list.Fields.Add("Address", SPFieldType.Text, false);
            list.Fields.Add("City", SPFieldType.Text, false);
            list.Fields.Add("Region", SPFieldType.Text, false);
            list.Fields.Add("PostalCode", SPFieldType.Text, false);
            list.Fields.Add("Country", SPFieldType.Text, false);
            list.Fields.Add("Phone", SPFieldType.Text, false);
            list.Fields.Add("Fax", SPFieldType.Text, false);

            list.Update();

            StringCollection fields = new StringCollection();
            fields.Add("CompanyName");
            fields.Add("ContactName");
            fields.Add("ContactTitle");
            fields.Add("Address");
            fields.Add("City");
            fields.Add("Region");
            fields.Add("PostalCode");
            fields.Add("Country");
            fields.Add("Phone");
            fields.Add("Fax");

            SPView view = list.Views.Add("My view", fields, list.DefaultView.Query, list.DefaultView.RowLimit, list.DefaultView.Paged, true);
            view.Update();

            return list;
        }
예제 #5
0
        private static SPView CreatePromotionsOnlyView(SPWeb currentWeb, SPList pagesList)
        {
            //Create View that only shows PromotionPage content type instances
            CAMLQueryBuilder queryBuilder = new CAMLQueryBuilder();

            queryBuilder.FilterByContentType(PromotionPageContentType);
            string queryBuilderBuildQuery = queryBuilder.Build().Query;

            //Add fields to list

            SPField productSkuField    = currentWeb.Site.RootWeb.Fields[new Guid(ProductSkuFieldId)];
            SPField promotionNameField = currentWeb.Site.RootWeb.Fields[new Guid(PromotionNameFieldId)];

            if (!pagesList.Fields.ContainsField(productSkuField.InternalName))
            {
                pagesList.Fields.Add(productSkuField);
            }
            if (!pagesList.Fields.ContainsField(promotionNameField.InternalName))
            {
                pagesList.Fields.Add(promotionNameField);
            }

            //Add fields to view using FieldId GUIDs
            StringCollection viewFields = new StringCollection();

            viewFields.Add(currentWeb.Site.RootWeb.Fields[new Guid(LinkFilenameFieldId)].InternalName); //LinkFilename)
            viewFields.Add(productSkuField.InternalName);                                               //ProductSkuField
            viewFields.Add(promotionNameField.InternalName);                                            //PromotionNameField

            SPView promotionsOnlyView = pagesList.Views.Add(PromotionOnlyView, viewFields, queryBuilderBuildQuery, 100, true, false);

            promotionsOnlyView.Update();

            return(promotionsOnlyView);
        }
        public void CreateListView(string viewName, string query, StringCollection collViewFields, uint rowLimit,
                                   bool paged, bool makeViewDefault, SPViewCollection.SPViewType viewType, bool personalView)
        {
            SPWeb website = null;

            try
            {
                website = GetWebSite();
                SPListCollection lists = website.Lists;
                SPList           list  = lists[ListName];

                list.Views.Add(viewName, collViewFields, query, rowLimit, paged, makeViewDefault, viewType, personalView);

                SPView view = list.Views[viewName];

                view.Update();
            }
            catch (Exception ex)
            {
                var log = new AppEventLog(AppException.ExceptionMessage(ex, "CreateListView", "ClsHelper"));
                log.WriteToLog();
            }
            finally
            {
                if (website != null)
                {
                    website.Dispose();
                }
            }
        }
예제 #7
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.Add(TitleField);
            view.ViewFields.Add(DescriptionField);
            view.Update();
        }
예제 #8
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add(EditField);
            view.ViewFields.Add(ProjectTitleField);
            view.Update();
        }
예제 #9
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add(UserNameField);
            view.ViewFields.Add(ListIDField);
            view.ViewFields.Add(ItemIDField);
            view.Update();
        }
        private void InstallListsViews(SPList list, int parentMessageId, XmlNode nodeView, string name, SPView view)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }
            if (nodeView == null)
            {
                throw new ArgumentNullException(nameof(nodeView));
            }
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }
            var fields          = nodeView.SelectSingleNode(Fields).InnerText.Split(SeparatorComma);
            var query           = ApplicationInstallerHelpers.getChildNodeText(nodeView, Query);
            var projectedFields = ApplicationInstallerHelpers.getChildNodeText(nodeView, ProjectedFields);
            var joins           = ApplicationInstallerHelpers.getChildNodeText(nodeView, Joins);

            uint iRowLimit = 0;

            uint.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, RowLimit), out iRowLimit);

            var bDefault = false;

            bool.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, MakeDefault), out bDefault);

            view.ViewFields.DeleteAll();

            foreach (var sField in fields)
            {
                SPField oField = null;
                try
                {
                    oField = list.Fields.GetFieldByInternalName(sField);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.ToString());
                }
                if (oField != null)
                {
                    view.ViewFields.Add(oField);
                }
            }

            view.Query           = query;
            view.ProjectedFields = projectedFields;
            view.Joins           = joins;
            view.RowLimit        = iRowLimit;
            view.DefaultView     = bDefault;
            view.Update();

            addMessage(ErrorLevels.Upgrade, name, "View exists and will overwrite", parentMessageId);
        }
예제 #11
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add(EditField);
            view.ViewFields.Add(ContentField);
            view.ViewFields.Add(ReadMoreField);
            view.ViewFields.Add(OrderField);
            view.Update();
        }
예제 #12
0
        private void CheckForQuickLaunchField(SPWeb spWeb)
        {
            spWeb.AllowUnsafeUpdates = true;

            SPList list = spWeb.Lists.TryGetList(INSTALLED_APPS);

            if (list != null)
            {
                if (!list.Fields.ContainsFieldWithInternalName("QuickLaunchOrder"))
                {
                    SPFieldNumber fldQuickLaunchOrder = (SPFieldNumber)list.Fields.CreateNewField(SPFieldType.Number.ToString(), "QuickLaunchOrder");

                    fldQuickLaunchOrder.Title         = "QuickLaunchOrder";
                    fldQuickLaunchOrder.DisplayFormat = SPNumberFormatTypes.NoDecimal;
                    fldQuickLaunchOrder.Indexed       = false;
                    list.Fields.Add(fldQuickLaunchOrder);
                    list.Update();

                    fldQuickLaunchOrder       = list.Fields["QuickLaunchOrder"] as SPFieldNumber;
                    fldQuickLaunchOrder.Title = "QuickLaunchOrder";
                    fldQuickLaunchOrder.ShowInListSettings = true;
                    fldQuickLaunchOrder.DefaultValue       = "1000";
                    fldQuickLaunchOrder.ShowInDisplayForm  = true;
                    fldQuickLaunchOrder.ShowInNewForm      = true;
                    fldQuickLaunchOrder.ShowInEditForm     = true;
                    fldQuickLaunchOrder.Hidden             = false;
                    fldQuickLaunchOrder.Update();

                    SPView tdefaultList = list.DefaultView;
                    tdefaultList.ViewFields.Add("QuickLaunchOrder");
                    tdefaultList.Update();

                    int     index = 0;
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><IsNull><FieldRef Name='EXTID'/></IsNull></Where><OrderBy><FieldRef Name='Title'/></OrderBy>";

                    foreach (SPListItem li in list.GetItems(query))
                    {
                        if (spWeb.ParentWeb == null && li["Title"].ToString().Equals("Global My Workplace", StringComparison.InvariantCultureIgnoreCase))
                        {
                            li["QuickLaunchOrder"] = "-1";
                        }
                        else
                        {
                            li["QuickLaunchOrder"] = index++;
                        }
                        li.Update();
                    }
                }
            }

            spWeb.AllowUnsafeUpdates = false;
        }
예제 #13
0
        private static void CreateLogTargets(SPManager mgr)
        {
            var list = CreateList(mgr, Constants.SpongeListLogtargets);

            list.Fields.Add("Xml", SPFieldType.Note, true);
            SPView view = list.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add("Title");
            view.ViewFields.Add("Xml");
            view.Update();
            list.Update();
        }
예제 #14
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add(EditField);
            view.ViewFields.Add(ProjectField);
            view.ViewFields.Add(QuoteField);
            view.ViewFields.Add(UserNameField);
            view.ViewFields.Add(RoleField);
            view.ViewFields.Add(FromField);
            view.Update();
        }
예제 #15
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.DeleteAll();
            view.ViewFields.Add(EditField);
            view.ViewFields.Add(ProjectField);
            view.ViewFields.Add(MessageTypeField);
            view.ViewFields.Add(MessageField);
            view.ViewFields.Add(DisplayField);
            view.ViewFields.Add(CreatedByField);
            view.Update();
        }
예제 #16
0
        protected override void UpdateDefaultView()
        {
            SPView view = List.DefaultView;

            view.ViewFields.Delete(LinkTitleField);
            view.ViewFields.Add(EditField);
            view.ViewFields.Add(CategoryField);
            view.ViewFields.Add(RoleField);
            view.ViewFields.Add(UserNameField);
            view.ViewFields.Add(EmailField);
            view.ViewFields.Add(ImageUrlField);
            view.Update();
        }
        private SPList ConfigureStyleDocumentLibrary(SPFeatureReceiverProperties properties)
        {
            SPSite site    = properties.Feature.Parent as SPSite;
            SPWeb  rootWeb = site.RootWeb;

            SPList list = null;

            try
            {
                SPListCollection lists = rootWeb.Lists;

                bool updateRequired = false;
                bool newListCreated = false;

                list = AddList(lists, "Style Library", "Style Library", "$Resources:cmscore,ListDescriptionRootStyles;", new Guid("00BFEA71-E717-4E80-AA17-D0C71B360101"), null, SPListTemplateType.DocumentLibrary, out newListCreated);
                //list = lists["Style Library"];

                if (list != null)
                {
                    EnableFolderCreationOnList(list, ref updateRequired);
                    if (list.AllowDeletion)
                    {
                        list.AllowDeletion = false;
                        updateRequired     = true;
                    }
                    if (updateRequired)
                    {
                        list.Update();
                    }
                    //EnableStandardVersioningOnList(list, ref updateRequired);
                    EnableAllowEveryoneViewItems(list);
                    DisableCrawlOnList(list);

                    list.Update();
                    SPView defaultView = list.DefaultView;
                    if (defaultView != null)
                    {
                        SPViewFieldCollection viewFields = defaultView.ViewFields;
                        AddFieldToView(list, SPBuiltInFieldId.CheckoutUser, viewFields);
                        defaultView.Update();
                    }

                    //AddFolder(list.RootFolder, "XSL Style Sheets");
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
            }
            return(list);
        }
        public static void ModifyView(SPView view, IEnumerable<string> ViewFields, string query)
        {
            // Validation
            view.RequireNotNull("view");

            ViewFields.RequireNotNull("ViewFields");
            ViewFields.RequireNotEmpty("ViewFields");
            query.RequireNotNullOrEmpty("query");

            view.Query = query;

            view.ViewFields.DeleteAll();
            foreach (string fieldName in ViewFields)
            {
                view.ViewFields.Add(fieldName);
            }
            view.Update();
        }
예제 #19
0
 public virtual void UpdateView(SPView view)
 {
     view.Update();
 }