none
Adding webparts in webpart zone when Page is created programmatically - (C#) - MOSS 2007

    Domanda

  • Have  to create a page with adding webparts to PageLayout Webpart zone dynamically when page is created.

    What is the way to achieve this using SharePoint objects using C#?

    UI or Webpart should  be like OOB create page (with PageLayout selection,Zone selection and webpart to be selected to particular zone).

    Note : not by adding webparts to PageLayouts..


    Marulasiddappa SB (Swamy)


    domenica 9 settembre 2012 11:39

Risposte

  • We can get pagelayout referred in the page using below code-- (there is no way to get zone Id present in pagelayoutrefered in Page)

     using (SPSite spSiteTest = new SPSite("http://test.com"))
                {
                    using (SPWeb spWebTest = spSiteTest.OpenWeb())
                    {

                        if (PublishingWeb.IsPublishingWeb(spWebTest))
                        {
                            SPList _list = spWebTest.Lists["Pages"];
                            string strPageName = "http://Test.com/Pages/TestPage.aspx";
                          

                            SPQuery query = new SPQuery();
                            query.Query = "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>" + strPageName + "</Value></Eq></Where>";
                            SPListItemCollection itemCollection = _list.GetItems(query);
                            query.RowLimit = 1;
                            if (itemCollection != null && itemCollection.Count == 1)
                            {
                                PublishingPage publishPage = PublishingPage.GetPublishingPage(itemCollection[0]);
                                string currentPageLayout = publishPage.Layout.Name;
                               
                                if (currentPageLayout.EndsWith(".aspx"))
                                {
                                    currentPageLayout = currentPageLayout.Substring(0, currentPageLayout.Length - 5);
                             
                                }
                            }
                        }


                    }
                }


    Marulasiddappa SB (Swamy)

    venerdì 14 settembre 2012 14:45

Tutte le risposte

  • Please refer to this thread - http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/1bc7212c-385d-4a89-9b7e-9d37ee762017


    Please "Mark as Answer" if a post has answered your question or "Vote as Helpful" if it was helpful in some way. Here's why

    domenica 9 settembre 2012 11:54
  • Thanks for the reply..

    I able to add webparts to webpart zone using below link

    http://www.keirgordon.com/post/Add-Web-Part-to-Page-Programmatically.aspx

    But, I have to all the zone id present in Page Layout which is referred in Page

    Any way to get Zone of Page layout reffered in Page? ( in a empty page with only zones)

    or

    Any way to get PageLayout referred in the page and get all zone id within PageLayout?


    Marulasiddappa SB (Swamy)


    mercoledì 12 settembre 2012 05:29
  • We can get pagelayout referred in the page using below code-- (there is no way to get zone Id present in pagelayoutrefered in Page)

     using (SPSite spSiteTest = new SPSite("http://test.com"))
                {
                    using (SPWeb spWebTest = spSiteTest.OpenWeb())
                    {

                        if (PublishingWeb.IsPublishingWeb(spWebTest))
                        {
                            SPList _list = spWebTest.Lists["Pages"];
                            string strPageName = "http://Test.com/Pages/TestPage.aspx";
                          

                            SPQuery query = new SPQuery();
                            query.Query = "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>" + strPageName + "</Value></Eq></Where>";
                            SPListItemCollection itemCollection = _list.GetItems(query);
                            query.RowLimit = 1;
                            if (itemCollection != null && itemCollection.Count == 1)
                            {
                                PublishingPage publishPage = PublishingPage.GetPublishingPage(itemCollection[0]);
                                string currentPageLayout = publishPage.Layout.Name;
                               
                                if (currentPageLayout.EndsWith(".aspx"))
                                {
                                    currentPageLayout = currentPageLayout.Substring(0, currentPageLayout.Length - 5);
                             
                                }
                            }
                        }


                    }
                }


    Marulasiddappa SB (Swamy)

    venerdì 14 settembre 2012 14:45