Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Webpart and zoneid

$
0
0

Hi,

consider the code below:

How do I find the value of zoneID that must be passed to the function AddWebpart?

When I set the default value "wpz" as referenced in several places in Internet, the webpart is not visible in the page.

When I replace it by "left" for example, the webpart is displayed in the page but not at the emplacement I'm willing.

I have found this interresting article ( http://blog.mastykarz.nl/programmatically-adding-web-parts-rich-content-sharepoint-2010/) that mentions to add the div section in the html code:

"<div class=\"ms-rtestate-read ms-rte-wpbox\" contentEditable=\"false\"><div class=\"ms-rtestate-read {0}\" id=\"div_{0}\"></div><div style='display:none' id=\"vid_{0}\"></div></div>"

And then add the wepbart by calling :  wpmgr.AddWebPart(cewp,"wpz", 0);

When I do that, the webbart is not displayed (but I can see that it has been correctly inserted in the page). It's just that it is not displayed/rendered.

Question: When I grab the html content of a page, and find the div section used to render the webpart, how do I determine the name of the zoneID that I should use programmatically?

 
        
       

 public void AddWebPartToWebPartPage(Web reqWeb, WebPartEntity webPart)
        {
            var webPartPage = _CurrentWebpage;
            LimitedWebPartManager limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
            reqWeb.Context.Load(limitedWebPartManager.WebParts,
                wps => wps.Include(
                wp => wp.WebPart.Title,
                wp => wp.WebPart.ZoneIndex));

            reqWeb.Context.ExecuteQuery();
            bool webPartExist = false;
            foreach (WebPartDefinition webpart in limitedWebPartManager.WebParts)
            {
                if (webpart.WebPart.Title == webPart.WebPartTitle)
                {
                    webPartExist = true;
                    break;
                }
            }

            if (webPartExist == false)
            {
                WebPartDefinition oWebPartDefinition = limitedWebPartManager.ImportWebPart(webPart.WebPartXml);
                limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, webPart.WebPartZone, webPart.WebPartIndex);
                reqWeb.Context.ExecuteQuery();
            }
        }



-- Emmanuel Dreux http://www.cloudiway.com




Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>