Пример #1
0
        private static void CreateSampleData(Web web) {
            var context = web.Context;
            var host = "https://" + HttpContext.Current.Request.Url.Authority;

            var event1 = new Event() {
                Title = "Corporate Event 1",
                Category = "Featured",
                ContactEmail = "*****@*****.**",
                Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet augue in dolor dapibus feugiat in eu odio. Proin vel egestas purus. Integer sit amet orci rhoncus, elementum nibh sit amet, maximus dui. Vivamus rutrum neque et massa hendrerit, varius consequat quam efficitur. Quisque aliquam pellentesque quam, a bibendum nibh dignissim sit amet. Curabitur accumsan tincidunt lectus et tincidunt.",
                ImageUrl = host + "/Images/company-events1.jpg",
                Location = "Pittsburgh, PA",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT001",
                EventDate = DateTime.Today.AddDays(25)
            };

            var event2 = new Event() {
                Title = "Corporate Event 2",
                Category = "Featured",
                ContactEmail = "*****@*****.**",
                Description = "Vestibulum ex mauris, feugiat in vehicula id, congue eleifend elit. Morbi orci quam, mattis sit amet nisl sed, dictum fermentum velit. Quisque rhoncus, arcu vitae dignissim tempus, nisl felis volutpat ipsum, non lobortis tellus lectus at mauris. Fusce porta, lectus feugiat egestas fringilla, dui velit tincidunt est, nec congue ligula urna a felis. Nam vitae ullamcorper lectus. Sed vitae justo felis.",
                ImageUrl = host + "/Images/company-events2.jpg",
                Location = "Helsinki, Finland",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT002",
                EventDate = DateTime.Today.AddDays(45)
            };

            var event3 = new Event() {
                Title = "Corporate Event 3",
                Category = "Featured",
                ContactEmail = "*****@*****.**",
                Description = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl = host + "/Images/company-events3.jpg",
                Location = "Chicago, IL",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT003",
                EventDate = DateTime.Today.AddDays(60)
            };

            var event4 = new Event() {
                Title = "Corporate Event 4",
                Category = "General",
                ContactEmail = "*****@*****.**",
                Description = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl = host + "/Images/company-events1.jpg",
                Location = "Chicago, IL",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT004",
                EventDate = DateTime.Today.AddDays(20)
            };

            var event5 = new Event() {
                Title = "Corporate Event 5",
                Category = "General",
                ContactEmail = "*****@*****.**",
                Description = "Vestibulum ex mauris, feugiat in vehicula id, congue eleifend elit. Morbi orci quam, mattis sit amet nisl sed, dictum fermentum velit. Quisque rhoncus, arcu vitae dignissim tempus, nisl felis volutpat ipsum, non lobortis tellus lectus at mauris. Fusce porta, lectus feugiat egestas fringilla, dui velit tincidunt est, nec congue ligula urna a felis. Nam vitae ullamcorper lectus. Sed vitae justo felis.",
                ImageUrl = host + "/Images/company-events2.jpg",
                Location = "Helsinki, Finland",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT005",
                EventDate = DateTime.Today.AddDays(45)
            };

            var event6 = new Event() {
                Title = "Corporate Event 6",
                Category = "General",
                ContactEmail = "*****@*****.**",
                Description = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl = host + "/Images/company-events3.jpg",
                Location = "Chicago, IL",
                Status = EventStatus.Active,
                RegisteredEventId = "EVT006",
                EventDate = DateTime.Today.AddDays(60)
            };

            event1.Save(web);
            event2.Save(web);
            event3.Save(web);
            event4.Save(web);
            event5.Save(web);
            event6.Save(web);

            // create default wiki page
            web.AddWikiPage("Site Pages", "EventsHome.aspx");

            # region web parts
            var webPart1 = new WebPartEntity(){
                WebPartXml = @"<webParts>
  <webPart xmlns='http://schemas.microsoft.com/WebPart/v3'>
    <metaData>
      <type name='Microsoft.SharePoint.WebPartPages.ClientWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name='Description' type='string'>Displays featured events</property>
        <property name='FeatureId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>3a6d7f41-2de8-4e69-b4b4-0325bd56b32c</property>
        <property name='Title' type='string'>Featured Events</property>
        <property name='ProductWebId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>12ae648f-27db-4a97-9c63-37155d3ace1e</property>
        <property name='WebPartName' type='string'>FeaturedEvents</property>
        <property name='ProductId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>3a6d7f41-2de8-4e69-b4b4-0325bd56b32b</property>
        <property name='ChromeState' type='chromestate'>Normal</property>
      </properties>
    </data>
  </webPart>
</webParts>",
                WebPartIndex = 0,
                WebPartTitle = "Featured Events",
                WebPartZone = "Rich Content"
            };

            var webPart2 = new WebPartEntity() {
                WebPartXml = @"<webParts>
  <webPart xmlns='http://schemas.microsoft.com/WebPart/v3'>
    <metaData>
      <type name='Microsoft.SharePoint.WebPartPages.ClientWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name='Description' type='string'>Events displayed by specific category</property>
        <property name='FeatureId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>3a6d7f41-2de8-4e69-b4b4-0325bd56b32c</property>
        <property name='Title' type='string'>Events</property>
        <property name='ProductWebId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>12ae648f-27db-4a97-9c63-37155d3ace1e</property>
        <property name='WebPartName' type='string'>Events</property>
        <property name='ProductId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>3a6d7f41-2de8-4e69-b4b4-0325bd56b32b</property>
        <property name='ChromeState' type='chromestate'>Normal</property>
      </properties>
    </data>
  </webPart>
</webParts>",
                WebPartIndex = 1,
                WebPartTitle = "Events",
                WebPartZone = "Rich Content"
            };
            #endregion

            var welcomePage = "SitePages/EventsHome.aspx";
            var serverRelativeUrl = UrlUtility.Combine(web.ServerRelativeUrl, welcomePage);

            File webPartPage = web.GetFileByServerRelativeUrl(serverRelativeUrl);

            if (webPartPage == null) {
                return;
            }

            web.Context.Load(webPartPage);
            web.Context.Load(webPartPage.ListItemAllFields);
            web.Context.Load(web.RootFolder);
            web.Context.ExecuteQuery();

            web.RootFolder.WelcomePage = welcomePage;
            web.RootFolder.Update();
            web.Context.ExecuteQuery();

            var limitedWebPartManager = webPartPage.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
            web.Context.Load(limitedWebPartManager.WebParts);
            web.Context.ExecuteQuery();

            for (var i = 0; i < limitedWebPartManager.WebParts.Count; i++) {
                limitedWebPartManager.WebParts[i].DeleteWebPart();
            }
            web.Context.ExecuteQuery();

            var oWebPartDefinition1 = limitedWebPartManager.ImportWebPart(webPart1.WebPartXml);
            var oWebPartDefinition2 = limitedWebPartManager.ImportWebPart(webPart2.WebPartXml);
            var wpdNew1 = limitedWebPartManager.AddWebPart(oWebPartDefinition1.WebPart, webPart1.WebPartZone, webPart1.WebPartIndex);
            var wpdNew2 = limitedWebPartManager.AddWebPart(oWebPartDefinition2.WebPart, webPart2.WebPartZone, webPart2.WebPartIndex);
            web.Context.Load(wpdNew1);
            web.Context.Load(wpdNew2);
            web.Context.ExecuteQuery();
        }
Пример #2
0
        private static void CreateSampleData(Web web)
        {
            var context = web.Context;
            var host    = "https://" + HttpContext.Current.Request.Url.Authority;

            var event1 = new Event()
            {
                Title             = "Corporate Event 1",
                Category          = "Featured",
                ContactEmail      = "*****@*****.**",
                Description       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet augue in dolor dapibus feugiat in eu odio. Proin vel egestas purus. Integer sit amet orci rhoncus, elementum nibh sit amet, maximus dui. Vivamus rutrum neque et massa hendrerit, varius consequat quam efficitur. Quisque aliquam pellentesque quam, a bibendum nibh dignissim sit amet. Curabitur accumsan tincidunt lectus et tincidunt.",
                ImageUrl          = host + "/Images/company-events1.jpg",
                Location          = "Pittsburgh, PA",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT001",
                EventDate         = DateTime.Today.AddDays(25)
            };

            var event2 = new Event()
            {
                Title             = "Corporate Event 2",
                Category          = "Featured",
                ContactEmail      = "*****@*****.**",
                Description       = "Vestibulum ex mauris, feugiat in vehicula id, congue eleifend elit. Morbi orci quam, mattis sit amet nisl sed, dictum fermentum velit. Quisque rhoncus, arcu vitae dignissim tempus, nisl felis volutpat ipsum, non lobortis tellus lectus at mauris. Fusce porta, lectus feugiat egestas fringilla, dui velit tincidunt est, nec congue ligula urna a felis. Nam vitae ullamcorper lectus. Sed vitae justo felis.",
                ImageUrl          = host + "/Images/company-events2.jpg",
                Location          = "Helsinki, Finland",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT002",
                EventDate         = DateTime.Today.AddDays(45)
            };

            var event3 = new Event()
            {
                Title             = "Corporate Event 3",
                Category          = "Featured",
                ContactEmail      = "*****@*****.**",
                Description       = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl          = host + "/Images/company-events3.jpg",
                Location          = "Chicago, IL",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT003",
                EventDate         = DateTime.Today.AddDays(60)
            };

            var event4 = new Event()
            {
                Title             = "Corporate Event 4",
                Category          = "General",
                ContactEmail      = "*****@*****.**",
                Description       = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl          = host + "/Images/company-events1.jpg",
                Location          = "Chicago, IL",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT004",
                EventDate         = DateTime.Today.AddDays(20)
            };

            var event5 = new Event()
            {
                Title             = "Corporate Event 5",
                Category          = "General",
                ContactEmail      = "*****@*****.**",
                Description       = "Vestibulum ex mauris, feugiat in vehicula id, congue eleifend elit. Morbi orci quam, mattis sit amet nisl sed, dictum fermentum velit. Quisque rhoncus, arcu vitae dignissim tempus, nisl felis volutpat ipsum, non lobortis tellus lectus at mauris. Fusce porta, lectus feugiat egestas fringilla, dui velit tincidunt est, nec congue ligula urna a felis. Nam vitae ullamcorper lectus. Sed vitae justo felis.",
                ImageUrl          = host + "/Images/company-events2.jpg",
                Location          = "Helsinki, Finland",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT005",
                EventDate         = DateTime.Today.AddDays(45)
            };

            var event6 = new Event()
            {
                Title             = "Corporate Event 6",
                Category          = "General",
                ContactEmail      = "*****@*****.**",
                Description       = "Vivamus scelerisque lectus et sapien mollis, ut vestibulum nunc vulputate. Nullam sed quam felis. Praesent sit amet egestas nunc, nec aliquam eros. Maecenas et nisl dapibus, varius metus ac, luctus quam. Donec vitae justo vitae nisi placerat ultrices nec sed ante.",
                ImageUrl          = host + "/Images/company-events3.jpg",
                Location          = "Chicago, IL",
                Status            = EventStatus.Active,
                RegisteredEventId = "EVT006",
                EventDate         = DateTime.Today.AddDays(60)
            };

            event1.Save(web);
            event2.Save(web);
            event3.Save(web);
            event4.Save(web);
            event5.Save(web);
            event6.Save(web);

            // create default wiki page
            web.AddWikiPage("Site Pages", "EventsHome.aspx");

            # region web parts