protected override void ExecuteCmdlet() { var serverRelativeWebUrl = CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); if (!ServerRelativePageUrl.ToLowerInvariant().StartsWith(serverRelativeWebUrl.ToLowerInvariant())) { ServerRelativePageUrl = UrlUtility.Combine(serverRelativeWebUrl, ServerRelativePageUrl); } WebPartEntity wp = null; switch (ParameterSetName) { case "FILE": if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } if (File.Exists(Path)) { var fileStream = new StreamReader(Path); var webPartString = fileStream.ReadToEnd(); fileStream.Close(); wp = new WebPartEntity { WebPartZone = ZoneId, WebPartIndex = ZoneIndex, WebPartXml = webPartString }; } break; case "XML": wp = new WebPartEntity { WebPartZone = ZoneId, WebPartIndex = ZoneIndex, WebPartXml = Xml }; break; } if (wp != null) { CurrentWeb.AddWebPartToWebPartPage(ServerRelativePageUrl, wp); } }