using System;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.WebParts;
namespace SampleCode
{
class DeleteWebPart
{
static void Main()
{
ClientContext oClientContext = new ClientContext("http://MyServer/sites/MySiteCollection");
File oFile = oClientContext.Web.GetFileByServerRelativeUrl("/sites/MySiteCollection/SitePages/Home.aspx ");
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
oClientContext.Load(limitedWebPartManager.WebParts);
oClientContext.ExecuteQuery();
if (limitedWebPartManager.WebParts.Count == 0)
{
throw new Exception("No Web Parts to delete.");
}
WebPartDefinition webPartDefinition = limitedWebPartManager.WebParts[0];
webPartDefinition.DeleteWebPart();
oClientContext.ExecuteQuery();
}
}
}
Showing posts with label client context sharepoint. Show all posts
Showing posts with label client context sharepoint. Show all posts
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 Part Default " +
"Use for formatted text, tables, and images. " +
"true 0 " +
"Normal true " +
"true true " +
"true true " +
"true true " +
"Modeless Default " +
"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.]]>" +
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=\"http://schemas.microsoft.com/WebPart/v2\">" +
"
"
"
"
"
"
"
"
"
"
"
"PublicKeyToken=94de0004b6e3fcc5
"
"
"
"
"
WebPartDefinition oWebPartDefinition = limitedWebPartManager.ImportWebPart(xmlWebPart);
limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, "Left", 1);
oClientContext.ExecuteQuery();
}
}
}
Updating the title of a Web Part
using System; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.WebParts; namespace SampleCode { class UpdateWebPartTitle { static void Main() { ClientContext oClientContext = new ClientContext("http://MyServer/sites/MySiteCollection"); File oFile = oClientContext.Web.GetFileByServerRelativeUrl("Default.aspx"); LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared); oClientContext.Load(limitedWebPartManager.WebParts, wps => wps.Include( wp => wp.WebPart.Title)); oClientContext.ExecuteQuery(); if (limitedWebPartManager.WebParts.Count == 0) { throw new Exception("No Web Parts on this page."); } WebPartDefinition oWebPartDefinition = limitedWebPartManager.WebParts[1]; WebPart oWebPart = oWebPartDefinition.WebPart; oWebPart.Title = "My New Web Part Title"; oWebPartDefinition.SaveWebPartChanges(); oClientContext.ExecuteQuery(); } } }
Subscribe to:
Posts (Atom)
Featured Posts
Kali Linux Remote Desktop: Access GNOME from Windows Using Native RDP
Kali Linux + GNOME 50 + GNOME Remote Desktop + Windows Remote Desktop (MSTSC) Getting a full GNOME desktop remotely on Kali Linux can be ...
-
public struct CoOrds { public int x, y; public CoOrds( int p1, int p2) { x = p1; y = p2; } }
-
LM Studio Overview LM Studio is a desktop application designed for developing and experimenting with large language models (LLMs)...