WebHosting

Thursday, July 7, 2011

Adding a Web Part to a page

using System;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.WebParts;

namespace SampleCode
{
class AddWebPart
{
static void Main()
{
ClientContext oClientContext = new ClientContext("http://MyServer/sites/MySiteCollection");
File oFile = oClientContext.Web.GetFileByServerRelativeUrl("Default.aspx");
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

string xmlWebPart = "" +
" " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns=\"http://schemas.microsoft.com/WebPart/v2\">" +
"My Web PartDefault" +
"Use for formatted text, tables, and images." +
"true0" +
"Normaltrue" +
"truetrue" +
"truetrue" +
"truetrue" +
"ModelessDefault" +
"Cannot import this Web Part." +
"/_layouts/images/mscontl.gif" +
"Microsoft.SharePoint, Version=13.0.0.0, Culture=neutral, " +
"PublicKeyToken=94de0004b6e3fcc5
" +
"Microsoft.SharePoint.WebPartPages.ContentEditorWebPart" +
"" +
"" +
" 
And this is a second paragraph.]]>" +
"";

WebPartDefinition oWebPartDefinition = limitedWebPartManager.ImportWebPart(xmlWebPart);

limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, "Left", 1);

oClientContext.ExecuteQuery();
}
}
}

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

OBS Browser Source Not Working? How to Interact With Web Pages Inside OBS Studio

If you're using OBS Studio to display a website, YouTube page, dashboard, live poll, chat widget, or web application, you may notice so...