protected override void ExecuteCmdlet() { var serverRelativeWebUrl = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant())) { ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl); } if (ParameterSetName == "NAME") { CurrentWeb.DeleteWebPart(ServerRelativePageUrl, Title); } else { var wps = CurrentWeb.GetWebParts(ServerRelativePageUrl); var wp = from w in wps where w.Id == Identity select w; var webPartDefinitions = wp as WebPartDefinition[] ?? wp.ToArray(); if (webPartDefinitions.Any()) { webPartDefinitions.FirstOrDefault().DeleteWebPart(); ClientContext.ExecuteQueryRetry(); } } }
protected override void ExecuteCmdlet() { var serverRelativeWebUrl = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant())) { ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl); } Guid id; if (Identity.Id == Guid.Empty) { var wp = CurrentWeb.GetWebParts(ServerRelativePageUrl).FirstOrDefault(wps => wps.WebPart.Title == Identity.Title); if (wp != null) { id = wp.Id; } else { throw new Exception($"Web Part with title '{Identity.Title}' cannot be found on page with URL {ServerRelativePageUrl}"); } } else { id = Identity.Id; } WriteObject(CurrentWeb.GetWebPartXml(id, ServerRelativePageUrl)); }
protected override void ExecuteCmdlet() { var serverRelativeWebUrl = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant())) { ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl); } var definitions = CurrentWeb.GetWebParts(ServerRelativePageUrl); if (Identity != null) { if (Identity.Id != Guid.Empty) { var wpfound = from wp in definitions where wp.Id == Identity.Id select wp; var webPartDefinitions = wpfound as WebPartDefinition[] ?? wpfound.ToArray(); if (webPartDefinitions.Any()) { WriteObject(webPartDefinitions.FirstOrDefault()); } } else if (!string.IsNullOrEmpty(Identity.Title)) { var wpfound = from wp in definitions where wp.WebPart.Title == Identity.Title select wp; var webPartDefinitions = wpfound as WebPartDefinition[] ?? wpfound.ToArray(); if (webPartDefinitions.Any()) { WriteObject(webPartDefinitions.FirstOrDefault()); } } } else { WriteObject(definitions, true); } }