Beispiel #1
0
        private void CreateNewsListView(SPWeb web, SPList list)
        {
            // create new view with custom webpart
            SPViewCollection allviews = list.Views;
            string           viewName = Constants.NEWS_LISTPAGE;

            System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();

            var view = allviews.Add(viewName, viewFields, string.Empty, 1, true, true);

            WebPartHelper.HideXsltListViewWebParts(web, view.Url);
            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = view.Url,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 0,
                            ZoneId      = "Main",
                            WebpartName = "NewsListView.webpart"
                        }
                    }
                }
            });
            WebPartHelper.MoveWebPart(web, view.Url, "NewsListView.webpart", "Main", 0);

            view.Update();
            //list.Update();
        }
Beispiel #2
0
        private void CreateWebpartInNewsHomepage(SPWeb web, SPList list)
        {
            string pageUrl = Constants.NEWS_HOME_PAGE;
            string zoneId  = "Header";

            int latestIdx = WebPartHelper.GetLatestWebPartIndex(web, pageUrl, zoneId);

            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = pageUrl,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            AllowDuplicate = true,
                            Index          = latestIdx + 1,
                            ZoneId         = zoneId,
                            Title          = list.Title,
                            WebpartName    = "ViewNewsCategoryWebPart.webpart",
                            Properties     = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "WebID",
                                    Value = web.ID.ToString(),
                                    Type  = "string"
                                },
                                new Property()
                                {
                                    Name  = "ListID",
                                    Value = list.ID.ToString(),
                                    Type  = "string"
                                },
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = list.Title
                                },
                                new Property()
                                {
                                    Name  = "TitleUrl",
                                    Value = list.DefaultViewUrl
                                },
                                new Property()
                                {
                                    Name  = "Description",
                                    Value = ""
                                }
                            }
                        }
                    }
                }
            });
        }
Beispiel #3
0
        // Uncomment the method below to handle the event raised before a feature is deactivated.

        //public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}

        #region Functions
        private void ProvisionWebpart(SPWeb web, string xmlFile)
        {
            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                string xml = assembly.GetResourceTextFile(xmlFile);

                var webpartPage = SerializationHelper.DeserializeFromXml<WebpartPageDefinitionCollection>(xml);

                WebPartHelper.ProvisionWebpart(web, webpartPage);
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }
Beispiel #4
0
        private void CreateDetailNewsPage(SPWeb web, SPList list)
        {
            var rootFolder = list.RootFolder;

            var dispFormUrl = string.Format("{0}/{1}/{2}.aspx", web.ServerRelativeUrl.TrimEnd('/'), rootFolder.Url, Constants.NEWS_DISPLAYPAGE);
            var dispForm    = web.GetFile(dispFormUrl);

            if (dispForm != null && dispForm.Exists)
            {
                dispForm.Delete();      // delete & recreate our display form
            }
            // create a new DispForm
            dispForm = rootFolder.Files.Add(dispFormUrl, SPTemplateFileType.FormPage);

            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = dispForm.Url,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 0,
                            ZoneId      = "Main",
                            WebpartName = "NewsDetailView.webpart",
                            Properties  = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = list.Title
                                },
                                new Property()
                                {
                                    Name  = "ChromeType",
                                    Type  = "chrometype",
                                    Value = "2"
                                }
                            }
                        }
                    }
                },
                new WebpartPageDefinition()
                {
                    PageUrl  = dispForm.Url,
                    Title    = "Other news",
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 2,
                            ZoneId      = "Main",
                            WebpartName = "OtherNewsListView.webpart",
                            Properties  = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = "Other news"
                                }
                            }
                        }
                    }
                }
            });

            dispForm.Update();
            //list.Update();
        }