public SPDocumentSetInstance AddDocumentSet(string name, object contentType, [DefaultParameterValue(null)] object properties, [DefaultParameterValue(true)] bool provisionDefaultContent) { var contentTypeId = SPContentTypeId.Empty; if (contentType is SPContentTypeIdInstance) { contentTypeId = (contentType as SPContentTypeIdInstance).ContentTypeId; } else if (contentType is SPContentTypeInstance) { contentTypeId = (contentType as SPContentTypeInstance).ContentType.Id; } else if (contentType is string) { contentTypeId = new SPContentTypeId(contentType as string); } if (contentTypeId == SPContentTypeId.Empty) { return(null); } var htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties); var docSet = DocumentSet.Create(m_folder, name, contentTypeId, htProperties, provisionDefaultContent); return(new SPDocumentSetInstance(Engine.Object.InstancePrototype, null, null, docSet)); }
public void SetFieldValues(object fieldValues) { var ht = SPHelper.GetFieldValuesHashtableFromPropertyObject(fieldValues); foreach (var key in ht.Keys) { var fieldName = TypeConverter.ToString(key); if (m_listItem.Fields.ContainsField(fieldName)) { m_listItem[fieldName] = ht[key]; } } }
public SPFileInstance Add(params object[] args) { var urlOfFile = TypeConverter.ToString(args.GetValue <object>(0)); var file = args.GetValue <Base64EncodedByteArrayInstance>(1); var properties = args.GetValue <object>(2); var createdBy = args.GetValue <object>(3); var modifiedBy = args.GetValue <object>(4); var timeCreated = args.GetValue <object>(5); var timeLastModified = args.GetValue <object>(6); var checkInComment = args.GetValue <object>(7); var overwrite = args.GetValue <object>(8); var requireWebFilePermissions = args.GetValue <object>(9); if (urlOfFile.IsNullOrWhiteSpace()) { throw new JavaScriptException(this.Engine, "Error", "File Url must be specified as the first parameter."); } if (file == null) { throw new JavaScriptException(this.Engine, "Error", "File Url must be specified as the first parameter."); } Hashtable htProperties = null; if (properties is HashtableInstance) { htProperties = (properties as HashtableInstance).Hashtable; } else if (properties != null && properties != Null.Value && properties != Undefined.Value) { htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties); } var uCreatedBy = SPBaristaContext.Current.Web.CurrentUser; if (createdBy is SPUserInstance) { uCreatedBy = (createdBy as SPUserInstance).User; } var uModifiedBy = SPBaristaContext.Current.Web.CurrentUser; if (modifiedBy is SPUserInstance) { uModifiedBy = (modifiedBy as SPUserInstance).User; } var dtTimeCreated = DateTime.UtcNow; if (timeCreated is DateInstance) { dtTimeCreated = (timeCreated as DateInstance).Value; } else if (timeCreated != null && timeCreated != Null.Value && timeCreated != Undefined.Value) { dtTimeCreated = new DateInstance(this.Engine.Object.InstancePrototype, DateInstance.Parse(TypeConverter.ToString(timeCreated))).Value; } var dtTimeLastModified = DateTime.UtcNow; if (timeLastModified is DateInstance) { dtTimeLastModified = (timeLastModified as DateInstance).Value; } else if (timeLastModified != null && timeLastModified != Null.Value && timeLastModified != Undefined.Value) { dtTimeLastModified = new DateInstance(this.Engine.Object.InstancePrototype, DateInstance.Parse(TypeConverter.ToString(timeLastModified))).Value; } string strCheckInComment = null; if (checkInComment != null && checkInComment != Null.Value && checkInComment != Undefined.Value) { strCheckInComment = TypeConverter.ToString(checkInComment); } var bOverwrite = false; if (overwrite != null && overwrite != Null.Value && overwrite != Undefined.Value) { bOverwrite = TypeConverter.ToBoolean(overwrite); } var bRequireWebFilePermissions = false; if (requireWebFilePermissions != null && requireWebFilePermissions != Null.Value && requireWebFilePermissions != Undefined.Value) { bRequireWebFilePermissions = TypeConverter.ToBoolean(requireWebFilePermissions); } using (var ms = new MemoryStream(file.Data)) { var result = m_fileCollection.Add(urlOfFile, ms, htProperties, uCreatedBy, uModifiedBy, dtTimeCreated, dtTimeLastModified, strCheckInComment, bOverwrite, bRequireWebFilePermissions); return(result == null ? null : new SPFileInstance(this.Engine.Object.InstancePrototype, result)); } }
public SPDocumentSetInstance CreateDocumentSet( [JSDoc("The folder to create the document set in.")] SPFolderInstance folder, [JSDoc("The name of the new document set.")] string name, [JSDoc("The content type id of the new documentset. Use new ContentTypeId('<CTID>')")] SPContentTypeIdInstance ctid, [JSDoc("Optional. Specifies a hashtable of fields that will be set on the document set where the key is the static field name.")] object properties, [JSDoc("Optional. Specifies a value that indicates if the default document set content will be provisioned. Default is true.")] object provisionDefaultContent, [JSDoc("Optional. Specifies the SPUser that created the document set.")] object user) { if (folder == null) { throw new JavaScriptException(this.Engine, "Error", "An instance of an SPFolder must be specified as the first argument."); } if (name.IsNullOrWhiteSpace()) { throw new JavaScriptException(this.Engine, "Error", "The name of the new document set must be specified."); } if (ctid == null) { throw new JavaScriptException(this.Engine, "Error", "The Content Type Id of the new document set must be specified."); } var htProperties = new Hashtable(); if (properties != null && properties != Null.Value && properties != Undefined.Value) { htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties); } var bProvisionDefaultContent = true; if (provisionDefaultContent != null && provisionDefaultContent != Null.Value && provisionDefaultContent != Undefined.Value) { bProvisionDefaultContent = TypeConverter.ToBoolean(provisionDefaultContent); } DocumentSet result; var spUser = user as SPUserInstance; if (user == null || user == Null.Value || user == Undefined.Value || spUser == null) { result = DocumentSet.Create(folder.Folder, name, ctid.ContentTypeId, htProperties, bProvisionDefaultContent); } else { result = DocumentSet.Create(folder.Folder, name, ctid.ContentTypeId, htProperties, bProvisionDefaultContent, spUser.User); } if (result == null) { return(null); } return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, folder.Folder.ParentWeb.Site, folder.Folder.ParentWeb, result)); }
public SPDocumentSetInstance Import(Base64EncodedByteArrayInstance bytes, string name, SPFolderInstance parentFolder, object ctid, object properties, object user) { if (bytes == null) { throw new JavaScriptException(this.Engine, "Error", "A base64 encoded byte array must be supplied as the first argument."); } if (name.IsNullOrWhiteSpace()) { throw new JavaScriptException(this.Engine, "Error", "The name of the new document set must be specified."); } if (parentFolder == null) { throw new JavaScriptException(this.Engine, "Error", "The parent folder must be specified."); } if (ctid == Undefined.Value && properties == Undefined.Value && user == Undefined.Value) { var r = DocumentSet.Import(bytes.Data, name, parentFolder.Folder); if (r == null) { return(null); } return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site, parentFolder.Folder.ParentWeb, r)); } var spCtId = ctid as SPContentTypeIdInstance; if (ctid == null || ctid == Null.Value || ctid == Undefined.Value || spCtId == null) { throw new JavaScriptException(this.Engine, "Error", "The Content Type Id of the imported document set must be specified."); } var spUser = user as SPUserInstance; if (user == null || user == Null.Value || user == Undefined.Value || spUser == null) { throw new JavaScriptException(this.Engine, "Error", "The user of the imported document set must be specified."); } var htProperties = new Hashtable(); if (properties != null && properties != Null.Value && properties != Undefined.Value) { htProperties = SPHelper.GetFieldValuesHashtableFromPropertyObject(properties); } var result = DocumentSet.Import(bytes.Data, name, parentFolder.Folder, spCtId.ContentTypeId, htProperties, spUser.User); if (result == null) { return(null); } return(new SPDocumentSetInstance(this.Engine.Object.InstancePrototype, parentFolder.Folder.ParentWeb.Site, parentFolder.Folder.ParentWeb, result)); }