protected override void ExecuteCmdlet() { var list = List.GetListOrThrow(nameof(List), CurrentWeb, l => l.RootFolder, l => l.ContentTypes); var listContentType = ContentType.GetContentType(list); if (listContentType is null) { var siteContentType = ContentType.GetContentTypeOrThrow(nameof(ContentType), CurrentWeb); listContentType = new ContentTypePipeBind(siteContentType.Name).GetContentTypeOrThrow(nameof(ContentType), list); } listContentType.EnsureProperty(ct => ct.StringId); if (!listContentType.StringId.StartsWith("0x0120D520")) { throw new PSArgumentException($"Content type '{ContentType}' does not inherit from the base Document Set content type. Document Set content type IDs start with 0x120D520"); } // Create the document set var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, listContentType.Id); ClientContext.ExecuteQueryRetry(); WriteObject(result.Value); }
protected override void ExecuteCmdlet() { var list = List.GetList(SelectedWeb); list.EnsureProperties(l => l.RootFolder, l => l.ContentTypes); // Try getting the content type from the Web var contentType = ContentType.GetContentType(SelectedWeb); // If content type could not be found but a content type ID has been passed in, try looking for the content type ID on the list instead if (contentType == null && !string.IsNullOrEmpty(ContentType.Id)) { contentType = list.ContentTypes.FirstOrDefault(ct => ct.StringId.Equals(ContentType.Id)); } else { // Content type has been found on the web, check if it also exists on the list if (list.ContentTypes.All(ct => !ct.StringId.Equals(contentType.Id.StringValue, System.StringComparison.InvariantCultureIgnoreCase))) { contentType = list.ContentTypes.FirstOrDefault(ct => ct.Name.Equals(ContentType.Name)); } } if (contentType == null) { throw new PSArgumentException("The provided contenttype has not been found", "ContentType"); } // Create the document set var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, contentType.Id); ClientContext.ExecuteQueryRetry(); WriteObject(result.Value); }
protected override void ExecuteCmdlet() { var ct = ContentType.GetContentType(SelectedWeb); var docSetTemplate = DocumentSet.GetDocumentSetTemplate(SelectedWeb); docSetTemplate.AllowedContentTypes.Remove(ct.Id); docSetTemplate.Update(true); ClientContext.ExecuteQuery(); }
protected override void ExecuteCmdlet() { var list = List.GetList(SelectedWeb); list.EnsureProperty(l => l.RootFolder); var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, ContentType.GetContentType(SelectedWeb).Id); ClientContext.ExecuteQueryRetry(); WriteObject(result.Value); }
protected override void ExecuteCmdlet() { Microsoft.SharePoint.Client.ContentType ct = null; if (string.IsNullOrEmpty(Folder)) { Folder = SessionState.Path.CurrentFileSystemLocation.Path; } else { if (!Path.IsPathRooted(Folder)) { Folder = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Folder); } } if (ContentType != null) { ct = ContentType.GetContentType(this.SelectedWeb); } if (TargetFolder == null) { TargetFolder = new DirectoryInfo(SessionState.Path.CurrentFileSystemLocation.Path).Name; } if (!string.IsNullOrEmpty(Out)) { if (!Path.IsPathRooted(Out)) { Out = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Out); } if (System.IO.File.Exists(Out)) { if (Force || ShouldContinue(string.Format(Commands.Properties.Resources.File0ExistsOverwrite, Out), Commands.Properties.Resources.Confirm)) { var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, SessionState.Path.CurrentFileSystemLocation.Path, Folder, ct != null ? ct.StringId : null); WriteObject(xml); } }
protected override void ExecuteCmdlet() { Microsoft.SharePoint.Client.ContentType ct = null; if (string.IsNullOrEmpty(Folder)) { Folder = SessionState.Path.CurrentFileSystemLocation.Path; } else { if (!Path.IsPathRooted(Folder)) { Folder = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Folder); Folder = new DirectoryInfo(Folder).FullName.TrimEnd('\\', '/'); // normalize away relative ./ paths } } if (ContentType != null) { ct = ContentType.GetContentType(SelectedWeb); } if (TargetFolder == null) { TargetFolder = new DirectoryInfo(SessionState.Path.CurrentFileSystemLocation.Path).Name; } if (!string.IsNullOrEmpty(Out)) { if (!ShouldContinue()) { return; } if (Path.GetExtension(Out).ToLower() == ".pnp") { byte[] pack = CreatePnPPackageFile(ct?.StringId); System.IO.File.WriteAllBytes(Out, pack); } else { var xml = CreateXmlAsStringFrom(ct?.StringId); System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = CreateXmlAsStringFrom(ct?.StringId); WriteObject(xml); } }
protected override void ExecuteCmdlet() { if (ParameterSpecified(nameof(Batch))) { var list = List.GetList(Batch); list.EnsureProperties(l => l.Id, l => l.Fields.LoadProperties(f => f.Id, f => f.Title, f => f.InternalName, f => f.TypeAsString)); var values = ListItemHelper.GetFieldValues(list, null, Values, ClientContext); if (ContentType != null) { var contentType = ContentType.GetContentType(Batch, list); values.Add("ContentTypeId", contentType.StringId); } list.Items.AddBatch(Batch.Batch, values, Folder); } else { List list = List.GetList(CurrentWeb); ListItemCreationInformation liCI = new ListItemCreationInformation(); if (Folder != null) { // Create the folder if it doesn't exist var rootFolder = list.EnsureProperty(l => l.RootFolder); var targetFolder = CurrentWeb.EnsureFolder(rootFolder, Folder); liCI.FolderUrl = targetFolder.ServerRelativeUrl; } var item = list.AddItem(liCI); bool systemUpdate = false; if (ContentType != null) { var ct = ContentType.GetContentType(list); if (ct != null) { item["ContentTypeId"] = ct.EnsureProperty(w => w.StringId); item.Update(); systemUpdate = true; ClientContext.ExecuteQueryRetry(); } } if (Values?.Count > 0) { ListItemHelper.SetFieldValues(item, Values, this); } if (!String.IsNullOrEmpty(Label)) { IList <Microsoft.SharePoint.Client.CompliancePolicy.ComplianceTag> tags = Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.GetAvailableTagsForSite(ClientContext, ClientContext.Url); ClientContext.ExecuteQueryRetry(); var tag = tags.Where(t => t.TagName == Label).FirstOrDefault(); if (tag != null) { item.SetComplianceTag(tag.TagName, tag.BlockDelete, tag.BlockEdit, tag.IsEventTag, tag.SuperLock); } else { WriteWarning("Can not find compliance tag with value: " + Label); } } if (systemUpdate) { item.SystemUpdate(); } else { item.Update(); } ClientContext.Load(item); ClientContext.ExecuteQueryRetry(); WriteObject(item); } }
protected override void ExecuteCmdlet() { #pragma warning disable CS0618 if (ParameterSpecified(nameof(SystemUpdate))) { UpdateType = ListItemUpdateType.SystemUpdate; } #pragma warning restore CS0618 if (ParameterSpecified(nameof(Batch))) { var list = List.GetList(Batch); if (list != null) { var item = Identity.GetListItem(list); if (item == null) { throw new PSArgumentException($"Cannot find item with Identity {Identity}", nameof(Identity)); } var values = ListItemHelper.GetFieldValues(list, item, Values, ClientContext, Batch); if (values == null) { values = new Dictionary <string, object>(); } if (ContentType != null) { var ct = ContentType.GetContentType(Batch, list); if (ct != null) { values.Add("ContentTypeId", ct.StringId); } } foreach (var value in values) { item[value.Key] = values[value.Key]; } switch (UpdateType) { case ListItemUpdateType.SystemUpdate: { item.SystemUpdateBatch(Batch.Batch); break; } case ListItemUpdateType.UpdateOverwriteVersion: { item.UpdateOverwriteVersionBatch(Batch.Batch); break; } case ListItemUpdateType.Update: { item.UpdateBatch(Batch.Batch); break; } } } } else { if (Identity == null || (Identity.Item == null && Identity.Id == 0)) { throw new PSArgumentException($"No -Identity has been provided specifying the item to update", nameof(Identity)); } List list; if (List != null) { list = List.GetList(CurrentWeb); } else { if (Identity.Item == null) { throw new PSArgumentException($"No -List has been provided specifying the list to update the item in", nameof(Identity)); } list = Identity.Item.ParentList; } if (list != null) { var item = Identity.GetListItem(list); if (ParameterSpecified(nameof(ClearLabel))) { item.SetComplianceTag(string.Empty, false, false, false, false, false); ClientContext.ExecuteQueryRetry(); } if (!string.IsNullOrEmpty(Label)) { var tags = Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.GetAvailableTagsForSite(ClientContext, ClientContext.Url); ClientContext.ExecuteQueryRetry(); var tag = tags.Where(t => t.TagName == Label).FirstOrDefault(); if (tag != null) { try { item.SetComplianceTag(tag.TagName, tag.BlockDelete, tag.BlockEdit, tag.IsEventTag, tag.SuperLock, false); ClientContext.ExecuteQueryRetry(); } catch (System.Exception error) { WriteWarning(error.Message.ToString()); } } else { WriteWarning("Can not find compliance tag with value: " + Label); } } if (ContentType != null) { ContentType ct = ContentType.GetContentType(list); if (ct != null) { item["ContentTypeId"] = ct.EnsureProperty(w => w.StringId);; ListItemHelper.UpdateListItem(item, UpdateType); ClientContext.ExecuteQueryRetry(); } } if (Values != null) { ListItemHelper.SetFieldValues(item, Values, this); ListItemHelper.UpdateListItem(item, UpdateType); } ClientContext.ExecuteQueryRetry(); ClientContext.Load(item); WriteObject(item); } } }
protected override void ExecuteCmdlet() { Microsoft.SharePoint.Client.ContentType ct = null; if (string.IsNullOrEmpty(Folder)) { Folder = SessionState.Path.CurrentFileSystemLocation.Path; } else { if (!Path.IsPathRooted(Folder)) { Folder = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Folder); } } if (ContentType != null) { ct = ContentType.GetContentType(this.SelectedWeb); } if (TargetFolder == null) { TargetFolder = new DirectoryInfo(SessionState.Path.CurrentFileSystemLocation.Path).Name; } if (!string.IsNullOrEmpty(Out)) { if (!Path.IsPathRooted(Out)) { Out = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Out); } if (System.IO.File.Exists(Out)) { if (Force || ShouldContinue(string.Format(Commands.Properties.Resources.File0ExistsOverwrite, Out), Commands.Properties.Resources.Confirm)) { var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); if (AsIncludeFile) { XElement xElement = XElement.Parse(xml); // Get the Files Element XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); if (filesElement != null) { xml = filesElement.ToString(); } } System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, new FileInfo(Out).DirectoryName, Folder, ct != null ? ct.StringId : null); if (AsIncludeFile) { XElement xElement = XElement.Parse(xml); // Get the Files Element XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); if (filesElement != null) { xml = filesElement.ToString(); } } System.IO.File.WriteAllText(Out, xml, Encoding); } } else { var xml = GetFiles(Schema, SessionState.Path.CurrentFileSystemLocation.Path, Folder, ct != null ? ct.StringId : null); if (AsIncludeFile) { XElement xElement = XElement.Parse(xml); // Get the Files Element XNamespace pnp = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12; var filesElement = xElement.Descendants(pnp + "Files").FirstOrDefault(); if (filesElement != null) { xml = filesElement.ToString(); } } WriteObject(xml); } }
protected override void ExecuteCmdlet() { if (ParameterSpecified(nameof(Batch))) { var list = List.GetList(Batch); if (list != null) { var item = Identity.GetListItem(list); if (item == null) { throw new PSArgumentException($"Cannot find item with Identity {Identity}"); } var values = ListItemHelper.GetFieldValues(list, Values, ClientContext); if (values == null) { values = new Dictionary <string, object>(); } if (ContentType != null) { var ct = ContentType.GetContentType(Batch, list); if (ct != null) { values.Add("ContentTypeId", ct.StringId); } } foreach (var value in values) { item[value.Key] = values[value.Key]; } if (SystemUpdate) { item.SystemUpdateBatch(Batch.Batch); } else { item.UpdateBatch(Batch.Batch); } } } else { List list = List.GetList(CurrentWeb); if (list != null) { var item = Identity.GetListItem(list); bool updateRequired = false; if (ContentType != null) { ContentType ct = ContentType.GetContentType(list); if (ct != null) { item["ContentTypeId"] = ct.EnsureProperty(w => w.StringId);; updateRequired = true; } } if (Values != null) { ListItemHelper.SetFieldValues(item, Values, this); updateRequired = true; } if (ParameterSpecified(nameof(ClearLabel))) { item.SetComplianceTag(string.Empty, false, false, false, false); ClientContext.ExecuteQueryRetry(); } if (!string.IsNullOrEmpty(Label)) { var tags = Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.GetAvailableTagsForSite(ClientContext, ClientContext.Url); ClientContext.ExecuteQueryRetry(); var tag = tags.Where(t => t.TagName == Label).FirstOrDefault(); if (tag != null) { try { item.SetComplianceTag(tag.TagName, tag.BlockDelete, tag.BlockEdit, tag.IsEventTag, tag.SuperLock); ClientContext.ExecuteQueryRetry(); } catch (System.Exception error) { WriteWarning(error.Message.ToString()); } } else { WriteWarning("Can not find compliance tag with value: " + Label); } } if (updateRequired) { var updateType = ListItemUpdateType.Update; if (SystemUpdate.IsPresent) { updateType = ListItemUpdateType.SystemUpdate; } ListItemHelper.UpdateListItem(item, updateType); } ClientContext.ExecuteQueryRetry(); ClientContext.Load(item); WriteObject(item); } } }