Beispiel #1
0
        private void ExecuteCopyListItem()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
            string    siteURL = GetSiteURL();
            int       id      = base.GetIntProperty(Constants.SOProperties.ID, true);

            string destinationURL       = base.GetStringProperty(Constants.SOProperties.DestinationURL, true);
            string destinationListTitle = base.GetStringProperty(Constants.SOProperties.DestinationListTitle, true);
            string destinationFolder    = base.GetStringProperty(Constants.SOProperties.DestinationFolder, false);
            string parentListTitle      = serviceObject.GetListTitle();

            //GetParentListItem
            ListItem parentListItem = GetSPListItem(siteURL, id, parentListTitle);
            //CopyItem to the destination List
            ListItem destinationListItem = CopyListItem(destinationURL, destinationListTitle, destinationFolder, parentListItem);


            DataRow dataRow = results.NewRow();

            dataRow[Constants.SOProperties.ID] = destinationListItem.Id;
            results.Rows.Add(dataRow);
        }
        private void ExecuteResetFolderInheritanceByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle  = serviceObject.GetListTitle();
            string siteURL    = GetSiteURL();
            string folderName = base.GetStringProperty(Constants.SOProperties.FolderName, true);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, d => d.RootFolder);
                context.ExecuteQuery();

                Folder currentFolder = null;
                try
                {
                    currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName.Trim('/')));
                    context.Load(currentFolder);
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                }

                currentFolder.ListItemAllFields.ResetRoleInheritance();
                context.ExecuteQuery();
            }
        }
Beispiel #3
0
        private void UpdateListItem()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle = serviceObject.GetListTitle();
            string siteURL   = GetSiteURL();
            int    id        = base.GetIntProperty(Constants.SOProperties.ID, true);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(listItem);

                foreach (Property prop in serviceObject.Properties)
                {
                    if (!string.IsNullOrEmpty(Convert.ToString(prop.Value)) && string.Compare(prop.Name, Constants.SOProperties.ID, true) != 0 && !prop.IsFile())
                    {
                        Helpers.SPHelper.AssignFieldValue(listItem, prop);
                    }
                }

                listItem.Update();
                context.ExecuteQuery();

                DataRow dataRow = results.NewRow();
                dataRow[Constants.SOProperties.ID] = listItem.Id;
                results.Rows.Add(dataRow);
            }
        }
        private void ExecuteDeleteFolder()
        {
            string        folderName    = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            bool          recursive     = base.GetBoolProperty(Constants.SOProperties.Recursively);
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];
            string        listTitle     = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);

            string siteURL = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                Folder folder = GetFolderByName(context, list, folderName);

                if (!recursive && folder.ItemCount > 0)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderIsNotEmpty, folderName));
                }

                folder.DeleteObject();

                context.ExecuteQuery();
            }
        }
        private void ExecuteAddFolderPermissionByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            string folderName  = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string userLogins  = base.GetStringProperty(Constants.SOProperties.UserLogins);
            string groupLogins = base.GetStringProperty(Constants.SOProperties.GroupLogins);
            string permission  = base.GetStringProperty(Constants.SOProperties.Permission, true);

            if (string.IsNullOrEmpty(userLogins) && string.IsNullOrEmpty(groupLogins))
            {
                throw new ApplicationException(Constants.ErrorMessages.UserGroupLoginsAreEmptyException);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, d => d.RootFolder);
                context.ExecuteQuery();

                Folder currentFolder = null;
                try
                {
                    currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName));
                    context.Load(currentFolder);
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                }

                var role = new RoleDefinitionBindingCollection(context);
                role.Add(context.Web.RoleDefinitions.GetByName(permission));

                if (!string.IsNullOrEmpty(userLogins))
                {
                    foreach (User user in GetUsersByLoginString(context, userLogins))
                    {
                        currentFolder.ListItemAllFields.RoleAssignments.Add(user, role);
                    }
                }

                if (!string.IsNullOrEmpty(groupLogins))
                {
                    foreach (Group group in GetGroupsByLoginString(context, groupLogins))
                    {
                        currentFolder.ListItemAllFields.RoleAssignments.Add(group, role);
                    }
                }
                currentFolder.Update();
                context.ExecuteQuery();
            }
        }
Beispiel #6
0
        private void GetItemsbyFolder()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results    = base.ServiceBroker.ServicePackage.ResultTable;
            string    siteURL    = GetSiteURL();
            string    listTitle  = serviceObject.GetListTitle();
            string    folderName = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string    folderPath = string.Empty;

            Properties searchProperties = Helpers.SPHelper.GetSearchFields(serviceObject.Properties);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list.Fields);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                if (!string.IsNullOrEmpty(folderName))
                {
                    folderPath = string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName);
                }
                else
                {
                    folderPath = list.RootFolder.ServerRelativeUrl;
                }

                CamlQuery calmQuery = Helpers.SPHelper.CreateCamlQuery(searchProperties, "BeginsWith", list);
                //Adding Folder Path
                calmQuery.FolderServerRelativeUrl = folderPath;

                IQueryable <ListItem> queryable = list.GetItems(calmQuery).IncludeWithDefaultProperties(item => item.ContentType);

                foreach (Field f in list.Fields)
                {
                    queryable.Concat((IEnumerable <ListItem>)queryable.Include(item => item[f.Title]));
                }

                IEnumerable <ListItem> source = context.LoadQuery(queryable);
                context.ExecuteQuery();
                foreach (ListItem listItem in source)
                {
                    DataRow dataRow = results.NewRow();
                    foreach (Property prop in serviceObject.Properties)
                    {
                        if (listItem.FieldValues.ContainsKey(prop.Name))
                        {
                            Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                        }
                    }
                    results.Rows.Add(dataRow);
                }
            }
        }
        private void ExecuteGetFolderPermissionByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            string folderName  = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string userOrGroup = base.GetStringProperty(Constants.SOProperties.UserOrGroup, true);
            string permissions = string.Empty;

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.RootFolder, l => l.DefaultDisplayFormUrl);
                context.ExecuteQuery();

                Folder currentFolder = null;

                try
                {
                    currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName));
                    context.Load(currentFolder);
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                }

                RoleAssignmentCollection roles = currentFolder.ListItemAllFields.RoleAssignments;
                context.Load(roles, role => role.Include(roleassigned => roleassigned.Member.LoginName, roleassigned => roleassigned.Member));
                context.ExecuteQuery();

                foreach (RoleAssignment role in roles)
                {
                    if (role.Member.LoginName == GetUserOrGroupLogin(context, userOrGroup))
                    {
                        RoleDefinitionBindingCollection roleDefinitions = role.RoleDefinitionBindings;
                        context.Load(roleDefinitions);
                        context.ExecuteQuery();

                        foreach (var roleDefinition in roleDefinitions)
                        {
                            DataRow dataRow = results.NewRow();
                            dataRow[Constants.SOProperties.Permission] = roleDefinition.Name;
                            results.Rows.Add(dataRow);
                        }
                    }
                }
            }
        }
        private void ExecuteCreateItem()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string folderPath = base.GetStringProperty(Constants.SOProperties.FolderName);

            string listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);
            string siteURL = GetSiteURL();

            DataRow dataRow = results.NewRow();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web             spWeb     = context.Web;
                List            list      = spWeb.Lists.GetByTitle(listTitle);
                FieldCollection fieldColl = list.Fields;

                context.Load(list, d => d.RootFolder.Name, d => d.DefaultDisplayFormUrl);
                context.Load(fieldColl);
                context.ExecuteQuery();

                ListItem newItem = null;

                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                itemCreateInfo.FolderUrl = string.Empty;
                if (!string.IsNullOrEmpty(folderPath))
                {
                    itemCreateInfo.FolderUrl = string.Format("{0}/lists/{1}/{2}", siteURL, list.Title, folderPath.Trim('/'));
                }

                newItem = list.AddItem(itemCreateInfo);

                foreach (Property prop in serviceObject.Properties)
                {
                    if (prop.Value != null && !prop.IsFile() && !prop.IsFolderName())
                    {
                        Helpers.SPHelper.AssignFieldValue(newItem, prop);
                    }
                }

                newItem[Constants.InternalProperties.ContentTypeId] = base.GetStringParameter(Constants.InternalProperties.ContentTypeId);

                newItem.Update();
                context.ExecuteQuery();

                dataRow[Constants.SOProperties.ID] = newItem.Id;
                string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, newItem.Id);
                dataRow[Constants.SOProperties.LinkToItem] = strurl;

                results.Rows.Add(dataRow);
            }
        }
        private void ExecuteDeleteDocSet()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results   = base.ServiceBroker.ServicePackage.ResultTable;
            DataRow   dataRow   = results.NewRow();
            string    listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);
            string siteURL    = GetSiteURL();
            string docSetName = base.GetStringProperty(Constants.SOProperties.DocSetName, true);
            string FolderName = string.Empty;

            if (serviceObject.IsSPFolderEnabled())
            {
                FolderName = base.GetStringProperty(Constants.SOProperties.FolderName, false);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web  spWeb = context.Web;
                List list  = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, l => l.Fields, l => l.RootFolder);
                context.Load(list, d => d.ItemCount);
                context.ExecuteQuery();

                if (list != null && list.ItemCount > 0)
                {
                    Folder documentSet = null;
                    if (string.IsNullOrEmpty(FolderName))
                    {
                        documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', docSetName));
                    }
                    else
                    {
                        documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', FolderName, '/', docSetName));
                    }

                    context.Load(documentSet, c => c.ListItemAllFields);
                    context.ExecuteQuery();

                    ListItem listItem = documentSet.ListItemAllFields;

                    if (listItem == null)
                    {
                        throw new Exception(Constants.ErrorMessages.RequiredDocNotFound);
                    }

                    listItem.DeleteObject();
                    context.ExecuteQuery();
                }
            }
        }
        private void ExecuteMoveFolder()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string destinationSiteURL     = base.GetStringProperty(Constants.SOProperties.DestinationURL, true);
            string destinationListLibrary = base.GetStringProperty(Constants.SOProperties.DestinationListLibrary, true);
            string destinationFolder      = base.GetStringProperty(Constants.SOProperties.DestinationFolder, false);
            string folderName             = base.GetStringProperty(Constants.SOProperties.FolderName, true);

            string listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);

            string siteURL = GetSiteURL();

            using (ClientContext sourceContext = InitializeContext(siteURL))
            {
                List sourceList = sourceContext.Web.Lists.GetByTitle(listTitle);
                sourceContext.Load(sourceList);
                sourceContext.Load(sourceList, l => l.Fields, l => l.RootFolder);
                sourceContext.ExecuteQuery();

                //get currentFolder in source list
                Folder sourceFolder = GetFolderByName(sourceContext, sourceList, folderName);

                //create destination context
                using (ClientContext destContext = InitializeContext(destinationSiteURL))
                {
                    List destList = destContext.Web.Lists.GetByTitle(destinationListLibrary);
                    destContext.Load(destList);
                    destContext.Load(destList, l => l.RootFolder, l => l.DefaultDisplayFormUrl);
                    destContext.ExecuteQuery();

                    //get or create destination folder
                    Folder destFolder = CreateFolderInternal(destContext.Web, destList, destList.RootFolder, string.Empty,
                                                             string.Concat(destinationFolder, '/', folderName.Split('/').Last()));

                    DataRow dataRow = results.NewRow();

                    CopyFolder(sourceContext, destContext, sourceList, destList, sourceFolder, destFolder);

                    destContext.Load(destFolder.ListItemAllFields);
                    destContext.ExecuteQuery();

                    string strurl = BuildListItemLink(destContext.Url, destList.DefaultDisplayFormUrl, destFolder.ListItemAllFields.Id);
                    dataRow[Constants.SOProperties.LinkToItem] = strurl;

                    results.Rows.Add(dataRow);
                }
            }
        }
        private void ExecuteGetItems()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);
            string     siteURL          = GetSiteURL();
            string     folderName       = base.GetStringProperty(Constants.SOProperties.FolderName);
            bool       recursive        = base.GetBoolProperty(Constants.SOProperties.Recursively);
            string     listtype         = serviceObject.MetaData.GetServiceElement <string>(Constants.InternalProperties.ListBaseType).ToString();
            Properties searchProperties = Helpers.SPHelper.GetSearchFields(serviceObject.Properties);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                IEnumerable <ListItem> source = FilterListItems(context, spWeb, list, searchProperties, folderName, recursive, "BeginsWith");

                foreach (ListItem listItem in source)
                {
                    DataRow dataRow = results.NewRow();

                    foreach (Property prop in serviceObject.Properties)
                    {
                        if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                        {
                            Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                        }
                        if (prop.IsFileName() && serviceObject.IsDocumentLibrary())
                        {
                            var fileName = (string)listItem.FieldValues[Constants.SharePointProperties.FileLeafRef].ToString();
                            dataRow[prop.Name] = fileName;
                        }
                        if (prop.IsLinkToItem())
                        {
                            string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                            dataRow[prop.Name] = strurl;
                        }
                    }
                    results.Rows.Add(dataRow);
                }
            }
        }
Beispiel #12
0
        private void GetListItemById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            int    id        = base.GetIntProperty(Constants.SOProperties.ID, true);
            string listTitle = serviceObject.GetListTitle();
            string siteURL   = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web      spWeb    = context.Web;
                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(list);
                context.Load(listItem);
                context.Load(listItem, i => i.File);
                context.ExecuteQuery();

                DataRow dataRow = results.NewRow();

                foreach (Property prop in serviceObject.Properties)
                {
                    if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                    {
                        Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                    }
                    if (prop.IsFile())
                    {
                        var fileRef = listItem.File.ServerRelativeUrl;
                        context.ExecuteQuery();
                        var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fileRef);
                        var fileName = (string)listItem.File.Name;
                        using (var fileStream = new System.IO.MemoryStream())
                        {
                            fileInfo.Stream.CopyTo(fileStream);

                            byte[] fileByte = fileStream.ToArray();

                            FileProperty propFile = new FileProperty(prop.Name, new MetaData(), fileName, System.Convert.ToBase64String(fileByte));

                            dataRow[prop.Name] = propFile.Value;//fileString.ToString();
                            dataRow[string.Format("{0}{1}", prop.Name, Constants.SOProperties.FileNameSuffix)] = fileName;
                            dataRow[string.Format("{0}{1}", prop.Name, Constants.SOProperties.FileURLSuffix)]  = new StringBuilder(siteURL).Append(fileRef).ToString();
                        }
                    }
                }
                results.Rows.Add(dataRow);
            }
        }
        private void ExecuteAddItemPermissionById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            int    id          = base.GetIntProperty(Constants.SOProperties.ID, true);
            string userLogins  = base.GetStringProperty(Constants.SOProperties.UserLogins);
            string groupLogins = base.GetStringProperty(Constants.SOProperties.GroupLogins);
            string permission  = base.GetStringProperty(Constants.SOProperties.Permission, true);

            if (string.IsNullOrEmpty(userLogins) && string.IsNullOrEmpty(groupLogins))
            {
                throw new ApplicationException(Constants.ErrorMessages.UserGroupLoginsAreEmptyException);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(listItem);
                context.ExecuteQuery();

                var role = new RoleDefinitionBindingCollection(context);
                role.Add(context.Web.RoleDefinitions.GetByName(permission));

                if (!string.IsNullOrEmpty(userLogins))
                {
                    foreach (User user in GetUsersByLoginString(context, userLogins))
                    {
                        listItem.RoleAssignments.Add(user, role);
                        listItem.Update();
                        context.ExecuteQuery();
                    }
                }

                if (!string.IsNullOrEmpty(groupLogins))
                {
                    foreach (Group group in GetGroupsByLoginString(context, groupLogins))
                    {
                        listItem.RoleAssignments.Add(group, role);
                        listItem.Update();
                        context.ExecuteQuery();
                    }
                }
            }
        }
        private void ExecuteGetItemById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            int    id        = base.GetIntProperty(Constants.SOProperties.ID, true);
            string listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);
            string siteURL = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web      spWeb    = context.Web;
                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(list);
                context.Load(list, i => i.DefaultDisplayFormUrl);
                context.Load(listItem);
                context.Load(listItem, i => i.File);
                context.ExecuteQuery();
                string test = list.DefaultDisplayFormUrl;

                DataRow dataRow = results.NewRow();

                foreach (Property prop in serviceObject.Properties)
                {
                    if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                    {
                        Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                    }
                    if (prop.IsFileName())
                    {
                        var fileName = (string)listItem.File.Name;
                        dataRow[prop.Name] = fileName;
                    }
                    if (prop.IsLinkToItem())
                    {
                        string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                        dataRow[prop.Name] = strurl;
                    }
                }
                results.Rows.Add(dataRow);
            }
        }
Beispiel #15
0
        private void ExecuteDeleteItemById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle = serviceObject.GetListTitle();
            string siteURL   = GetSiteURL();
            int    id        = base.GetIntProperty(Constants.SOProperties.ID, true);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web      spWeb    = context.Web;
                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                listItem.DeleteObject();
                context.ExecuteQuery();
            }
        }
        private void ExecuteGetItemPermissionById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            int    id          = base.GetIntProperty(Constants.SOProperties.ID, true);
            string userOrGroup = base.GetStringProperty(Constants.SOProperties.UserOrGroup, true);
            string permissions = string.Empty;

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(listItem);
                context.ExecuteQuery();

                RoleAssignmentCollection roles = listItem.RoleAssignments;
                context.Load(roles, role => role.Include(roleassigned => roleassigned.Member.LoginName, roleassigned => roleassigned.Member));
                context.ExecuteQuery();

                foreach (RoleAssignment role in roles)
                {
                    if (role.Member.LoginName == GetUserOrGroupLogin(context, userOrGroup))
                    {
                        RoleDefinitionBindingCollection roleDefinitions = role.RoleDefinitionBindings;
                        context.Load(roleDefinitions);
                        context.ExecuteQuery();

                        foreach (var roleDefinition in roleDefinitions)
                        {
                            DataRow dataRow = results.NewRow();
                            dataRow[Constants.SOProperties.Permission] = roleDefinition.Name;
                            results.Rows.Add(dataRow);
                        }
                    }
                }
            }
        }
        private void ExecuteRenameFolder()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listTitle);

            string siteURL               = GetSiteURL();
            string folderName            = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string destinationFolderName = base.GetStringProperty(Constants.SOProperties.DestinationFolder, true);

            folderName = folderName.Trim('/');

            DataRow dataRow = results.NewRow();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.RootFolder, l => l.DefaultDisplayFormUrl);
                context.ExecuteQuery();

                Folder currentFolder = GetFolderByName(context, list, folderName);

                ListItem folderItem = currentFolder.ListItemAllFields;
                context.Load(folderItem);
                context.ExecuteQuery();

                folderItem[Constants.InternalProperties.FileLeafRef] = destinationFolderName.Trim('/').Split('/')[0];
                folderItem.Update();
                context.ExecuteQuery();

                string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, folderItem.Id);
                dataRow[Constants.SOProperties.LinkToItem] = strurl;

                results.Rows.Add(dataRow);
            }
        }
        private void ExecuteCreateFolder()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string folderName = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string listName   = serviceObject.GetListTitle();

            GetDynamicListTitle(ref listName);

            string siteURL = GetSiteURL();

            DataRow dataRow = results.NewRow();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web  spWeb = context.Web;
                List list  = spWeb.Lists.GetByTitle(listName);
                context.Load(list);
                context.Load(list, l => l.DefaultDisplayFormUrl);
                context.ExecuteQuery();

                if (!serviceObject.IsSPFolderEnabled())
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderCreationIsNotSupported, listName));
                }

                Folder folder = CreateFolderInternal(spWeb, list, list.RootFolder, string.Empty, folderName);

                context.Load(folder.ListItemAllFields);
                context.ExecuteQuery();

                string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, folder.ListItemAllFields.Id);
                dataRow[Constants.SOProperties.LinkToItem] = strurl;

                results.Rows.Add(dataRow);
            }
        }
Beispiel #19
0
        private void CreateFolder()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];
            string        folderName    = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string        listName      = serviceObject.GetListTitle();
            string        siteURL       = GetSiteURL();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web  spWeb = context.Web;
                List list  = spWeb.Lists.GetByTitle(listName);
                context.Load(list);
                context.ExecuteQuery();

                //TODO: get this information from the ServiceObject
                if (!list.EnableFolderCreation)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderCreationIsNotSupported, listName));
                }

                CreateFolderInternal(spWeb, list, list.RootFolder, string.Empty, folderName);
            }
        }
        private void ExecuteGetDocumentSets()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string     listTitle        = serviceObject.GetListTitle();
            string     siteURL          = GetSiteURL();
            string     DocSetName       = base.GetStringProperty(Constants.SOProperties.DocSetName, false);
            string     folderName       = base.GetStringProperty(Constants.SOProperties.FolderName);
            bool       recursive        = base.GetBoolProperty(Constants.SOProperties.Recursively);
            string     folderPath       = string.Empty;
            Properties searchProperties = Helpers.SPHelper.GetSearchFields(serviceObject.Properties);

            if (!string.IsNullOrEmpty(DocSetName))
            {
                Property fileLeafRefProperty = NewProperty(Constants.InternalProperties.FileLeafRef, Constants.InternalProperties.FileLeafRef, true, SoType.Text, "");
                fileLeafRefProperty.Value = DocSetName;
                fileLeafRefProperty.MetaData.ServiceProperties.Add(Constants.InternalProperties.Internal, false);
                fileLeafRefProperty.MetaData.ServiceProperties.Add(Constants.InternalProperties.SPFieldType, "Text");
                searchProperties.Add(fileLeafRefProperty);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                IEnumerable <ListItem> source = FilterListItems(context, spWeb, list, searchProperties, folderName, recursive, "BeginsWith", true);

                foreach (ListItem listItem in source)
                {
                    if (listItem.FileSystemObjectType == FileSystemObjectType.Folder)
                    {
                        DataRow dataRow = results.NewRow();
                        foreach (Property prop in serviceObject.Properties)
                        {
                            if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                            {
                                Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                            }
                            if (prop.IsDocSetName())
                            {
                                dataRow[prop.Name] = (string)listItem.FieldValues[Constants.SharePointProperties.FileLeafRef].ToString();
                            }

                            if (prop.IsLinkToItem())
                            {
                                string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                                dataRow[prop.Name] = strurl;
                            }
                        }
                        results.Rows.Add(dataRow);
                    }
                }
            }
        }
        private void ExecuteGetDocSetByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            DataRow dataRow    = results.NewRow();
            string  listTitle  = serviceObject.GetListTitle();
            string  DocSetName = base.GetStringProperty(Constants.SOProperties.DocSetName, true);
            string  FolderName = string.Empty;

            if (serviceObject.IsSPFolderEnabled())
            {
                FolderName = base.GetStringProperty(Constants.SOProperties.FolderName, false);
            }


            using (ClientContext context = InitializeContext(GetSiteURL()))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl);
                context.Load(list.RootFolder);
                context.Load(list.RootFolder.Folders);
                context.ExecuteQuery();

                Folder documentSet = null;
                if (string.IsNullOrEmpty(FolderName))
                {
                    documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', DocSetName));
                }
                else
                {
                    documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', FolderName, '/', DocSetName));
                }

                context.Load(documentSet, c => c.ListItemAllFields);
                context.ExecuteQuery();

                ListItem listItem = documentSet.ListItemAllFields;


                foreach (Property prop in serviceObject.Properties)
                {
                    if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                    {
                        Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                    }

                    if (prop.IsLinkToItem())
                    {
                        string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                        dataRow[prop.Name] = strurl;
                    }
                }
                results.Rows.Add(dataRow);
            }
        }
Beispiel #22
0
        private void ExecuteGetItemByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle  = serviceObject.GetListTitle();
            string siteURL    = GetSiteURL();
            string folderName = base.GetStringProperty(Constants.SOProperties.FolderName);
            bool   recursive  = base.GetBoolProperty(Constants.SOProperties.Recursively);
            string folderPath = string.Empty;

            //add FileLeafRef property for filter by File Name
            Property fileLeafRefProperty = NewProperty(Constants.InternalProperties.FileLeafRef, Constants.InternalProperties.FileLeafRef, true, SoType.Text, "");

            fileLeafRefProperty.Value = serviceObject.Properties.Where(p => p.IsFileName()).FirstOrDefault().Value;
            fileLeafRefProperty.MetaData.ServiceProperties.Add(Constants.InternalProperties.Internal, false);
            fileLeafRefProperty.MetaData.ServiceProperties.Add(Constants.InternalProperties.SPFieldType, "Text");
            Properties searchProperties = new Properties {
                fileLeafRefProperty
            };

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                IEnumerable <ListItem> source = FilterListItems(context, spWeb, list, searchProperties, folderName, recursive, "Eq");

                foreach (ListItem listItem in source)
                {
                    DataRow dataRow = results.NewRow();

                    context.Load(listItem, i => i.File);
                    context.ExecuteQuery();

                    foreach (Property prop in serviceObject.Properties)
                    {
                        if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                        {
                            Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                        }
                        if (prop.IsFileName())
                        {
                            var fileName = (string)listItem.File.Name;
                            dataRow[prop.Name] = fileName;
                        }
                        if (prop.IsLinkToItem())
                        {
                            string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                            dataRow[prop.Name] = strurl;
                        }
                    }
                    results.Rows.Add(dataRow);
                }
            }
        }
Beispiel #23
0
        private void ExecuteGetItemByTitle()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle  = serviceObject.GetListTitle();
            string siteURL    = GetSiteURL();
            string folderName = base.GetStringProperty(Constants.SOProperties.FolderName);
            bool   recursive  = base.GetBoolProperty(Constants.SOProperties.Recursively);
            string folderPath = string.Empty;


            Properties searchProperties = Helpers.SPHelper.GetSearchFields(serviceObject.Properties);

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list);
                context.Load(list, l => l.Fields, l => l.DefaultDisplayFormUrl);
                context.Load(list.RootFolder);
                context.ExecuteQuery();

                if (!string.IsNullOrEmpty(folderName))
                {
                    folderPath = string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName);
                    Folder folder;
                    try
                    {
                        folder = spWeb.GetFolderByServerRelativeUrl(folderPath);
                        context.Load(folder);
                        context.ExecuteQuery();
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                    }
                }
                else
                {
                    folderPath = list.RootFolder.ServerRelativeUrl;
                }

                CamlQuery camlQuery = Helpers.SPHelper.CreateCamlQuery(searchProperties, "Eq", list, recursive);
                camlQuery.FolderServerRelativeUrl = folderPath;

                IQueryable <ListItem> queryable = list.GetItems(camlQuery).IncludeWithDefaultProperties <ListItem>(item => item.ContentType);

                foreach (Field f in list.Fields)
                {
                    queryable.Concat <ListItem>((IEnumerable <ListItem>)queryable.Include <ListItem>(item => item[f.Title]));
                }

                IEnumerable <ListItem> source = context.LoadQuery(queryable);
                context.ExecuteQuery();
                foreach (ListItem listItem in source)
                {
                    DataRow dataRow = results.NewRow();

                    context.Load(listItem, i => i.File);
                    context.ExecuteQuery();

                    foreach (Property prop in serviceObject.Properties)
                    {
                        if (listItem.FieldValues.ContainsKey(prop.Name) && !prop.IsFile())
                        {
                            Helpers.SPHelper.AddFieldValue(dataRow, prop, listItem);
                        }
                        if (prop.IsLinkToItem())
                        {
                            string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                            dataRow[prop.Name] = strurl;
                        }
                    }
                    results.Rows.Add(dataRow);
                }
            }
        }
        private void ExecuteRemoveFolderPermissionByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            string folderName  = base.GetStringProperty(Constants.SOProperties.FolderName, true);
            string userLogins  = base.GetStringProperty(Constants.SOProperties.UserLogins);
            string groupLogins = base.GetStringProperty(Constants.SOProperties.GroupLogins);

            if (string.IsNullOrEmpty(userLogins) && string.IsNullOrEmpty(groupLogins))
            {
                throw new ApplicationException(Constants.ErrorMessages.UserGroupLoginsAreEmptyException);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List list = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, d => d.RootFolder);
                context.ExecuteQuery();

                Folder currentFolder = null;
                try
                {
                    currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, folderName));
                    context.Load(currentFolder);
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.FolderWasNotFound, folderName), ex);
                }

                RoleAssignmentCollection roles = currentFolder.ListItemAllFields.RoleAssignments;
                context.Load(roles, role => role.Include(roleassigned => roleassigned.Member.LoginName, roleassigned => roleassigned.Member));
                context.ExecuteQuery();

                if (!string.IsNullOrEmpty(userLogins))
                {
                    foreach (User user in GetUsersByLoginString(context, userLogins))
                    {
                        context.Load(user, u => u.LoginName);
                        context.ExecuteQuery();

                        foreach (RoleAssignment role in roles)
                        {
                            if (role.Member.LoginName == user.LoginName)
                            {
                                role.DeleteObject();
                                break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(groupLogins))
                {
                    foreach (Group group in GetGroupsByLoginString(context, groupLogins))
                    {
                        context.Load(group, g => g.LoginName);
                        context.ExecuteQuery();

                        foreach (RoleAssignment role in roles)
                        {
                            if (role.Member.LoginName == group.LoginName)
                            {
                                role.DeleteObject();
                                break;
                            }
                        }
                    }
                }

                context.ExecuteQuery();
            }
        }
Beispiel #25
0
        private void CreateListItem()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle = serviceObject.GetListTitle();
            string siteURL   = GetSiteURL();

            DataRow dataRow = results.NewRow();

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web             spWeb     = context.Web;
                List            list      = spWeb.Lists.GetByTitle(listTitle);
                FieldCollection fieldColl = list.Fields;

                context.Load(list, d => d.RootFolder.Name);
                context.Load(fieldColl);
                context.ExecuteQuery();

                ListItem newItem = null;

                //get folder path
                string folderPath = string.Empty;
                if (serviceObject.Properties[Constants.SOProperties.FolderName].Value != null)
                {
                    folderPath = serviceObject.Properties[Constants.SOProperties.FolderName].Value.ToString();
                }
                if (!serviceObject.IsDocumentLibrary())
                {
                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    itemCreateInfo.FolderUrl = string.Empty;
                    if (!string.IsNullOrEmpty(folderPath))
                    {
                        itemCreateInfo.FolderUrl = string.Format("{0}/lists/{1}/{2}", siteURL, list.Title, folderPath.Trim('/'));
                    }

                    newItem = list.AddItem(itemCreateInfo);
                }
                else
                {
                    FileCreationInformation fileCreateInfo = new FileCreationInformation();
                    //TODO: XmlDocument would load everything into memory.
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(serviceObject.Properties[Constants.InternalProperties.FileLeafRef].Value.ToString());
                    foreach (XmlNode xn in xmlDocument)
                    {
                        XmlNode name    = xn.SelectSingleNode("name");
                        XmlNode content = xn.SelectSingleNode("content");
                        if (name != null)
                        {
                            if (string.IsNullOrEmpty(folderPath))
                            {
                                fileCreateInfo.Url = string.Concat(GetSiteURL(), "/", list.RootFolder.Name, "/", name.InnerText);
                            }
                            else
                            {
                                fileCreateInfo.Url = string.Concat(GetSiteURL(), "/", list.RootFolder.Name, "/", folderPath, "/", name.InnerText);
                            }
                        }
                        if (content != null)
                        {
                            // byte[] fileContent = Convert.FromBase64String(content.InnerText);
                            //fileCreateInfo.Content = fileContent;
                            fileCreateInfo.ContentStream = new System.IO.MemoryStream(Convert.FromBase64String(content.InnerText));
                        }
                    }
                    fileCreateInfo.Overwrite = true;

                    File newFile = null;
                    if (string.IsNullOrEmpty(folderPath))
                    {
                        newFile = list.RootFolder.Files.Add(fileCreateInfo);
                    }
                    else
                    {
                        Folder currentFolder = spWeb.GetFolderByServerRelativeUrl(string.Format("{0}/{1}", list.RootFolder.Name, folderPath.Trim('/')));
                        context.Load(currentFolder);
                        context.ExecuteQuery();

                        newFile = currentFolder.Files.Add(fileCreateInfo);
                    }

                    context.Load(newFile);
                    context.ExecuteQuery();

                    newItem = newFile.ListItemAllFields;

                    context.Load(newItem);
                    context.ExecuteQuery();
                }

                foreach (Property prop in serviceObject.Properties)
                {
                    if (prop.Value != null && !prop.IsFile() && string.Compare(prop.Name, Constants.SOProperties.FolderName, true) != 0)
                    {
                        Helpers.SPHelper.AssignFieldValue(newItem, prop);
                    }
                }

                newItem.Update();
                context.ExecuteQuery();

                dataRow[Constants.SOProperties.ID] = newItem.Id;

                results.Rows.Add(dataRow);
            }
        }
        private void ExecuteRenameDocSet()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results       = base.ServiceBroker.ServicePackage.ResultTable;
            DataRow   dataRow       = results.NewRow();
            string    listTitle     = serviceObject.GetListTitle();
            string    siteURL       = GetSiteURL();
            string    docSetName    = base.GetStringProperty(Constants.SOProperties.DocSetName, true);
            string    newDocSetName = base.GetStringProperty(Constants.SOProperties.DocSetNewName, true);
            string    FolderName    = string.Empty;

            if (serviceObject.IsSPFolderEnabled())
            {
                FolderName = base.GetStringProperty(Constants.SOProperties.FolderName, false);
            }


            using (ClientContext context = InitializeContext(siteURL))
            {
                Web  spWeb = context.Web;
                List list  = spWeb.Lists.GetByTitle(listTitle);
                context.Load(list, l => l.Fields, l => l.RootFolder);
                context.Load(list, d => d.DefaultDisplayFormUrl, d => d.ItemCount);
                context.ExecuteQuery();

                if (list != null && list.ItemCount > 0)
                {
                    Folder documentSet = null;
                    if (string.IsNullOrEmpty(FolderName))
                    {
                        documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', docSetName));
                    }
                    else
                    {
                        documentSet = context.Web.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', FolderName, '/', docSetName));
                    }

                    context.Load(documentSet, c => c.ListItemAllFields);
                    context.ExecuteQuery();

                    ListItem listItem = documentSet.ListItemAllFields;

                    if (listItem == null)
                    {
                        throw new Exception(Constants.ErrorMessages.RequiredDocNotFound);
                    }

                    foreach (Property prop in serviceObject.Properties)
                    {
                        if (prop.Value != null && prop.IsNewDocumentSetName())
                        {
                            listItem[Constants.SharePointProperties.FileLeafRef] = prop.Value;
                        }
                    }
                    listItem.Update();
                    context.ExecuteQuery();

                    string strurl = BuildListItemLink(context.Url, list.DefaultDisplayFormUrl, listItem.Id);
                    dataRow[Constants.SOProperties.LinkToItem] = strurl;
                    results.Rows.Add(dataRow);
                }
            }
        }
        private void ExecuteCreateDocSetByName()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            string listTitle  = serviceObject.GetListTitle();
            string DocSetName = base.GetStringProperty(Constants.SOProperties.DocSetName, true);
            string FolderName = string.Empty;

            if (serviceObject.IsSPFolderEnabled())
            {
                FolderName = base.GetStringProperty(Constants.SOProperties.FolderName, false);
            }

            DataRow dataRow = results.NewRow();

            using (ClientContext context = InitializeContext(GetSiteURL()))
            {
                Web    spWeb = context.Web;
                List   list  = spWeb.Lists.GetByTitle(listTitle);
                Folder parentFolder;
                context.Load(list, l => l.Fields, l => l.RootFolder);
                context.Load(list, d => d.DefaultDisplayFormUrl, d => d.ItemCount);
                context.Load(list.ContentTypes);
                context.ExecuteQuery();

                if (string.IsNullOrEmpty(FolderName))
                {
                    parentFolder = list.RootFolder;
                }
                else
                {
                    parentFolder = spWeb.GetFolderByServerRelativeUrl(string.Concat(list.RootFolder.Name, '/', FolderName));
                    context.Load(parentFolder);
                    context.ExecuteQuery();
                }

                Microsoft.SharePoint.Client.ClientResult <string> FileLink = new ClientResult <string>();
                foreach (ContentType ct in list.ContentTypes)
                {
                    if (ct.Id.StringValue.StartsWith(Constants.SharePointProperties.DocSetContentType))
                    {
                        FileLink = DocumentSet.Create(context, parentFolder, DocSetName, ct.Id);
                        break;
                    }
                }
                context.ExecuteQuery();

                Folder documentSet = null;
                documentSet = context.Web.GetFolderByServerRelativeUrl(FileLink.Value);
                context.Load(documentSet, c => c.ListItemAllFields);
                context.ExecuteQuery();

                ListItem listItem = documentSet.ListItemAllFields;

                if (listItem == null)
                {
                    throw new Exception(Constants.ErrorMessages.RequiredDocNotFound);
                }

                foreach (Property prop in serviceObject.Properties)
                {
                    if (prop.Value != null && !prop.IsDocSetName() && !prop.IsFolderName())
                    {
                        Helpers.SPHelper.AssignFieldValue(listItem, prop);
                    }
                }
                listItem.Update();
                context.ExecuteQuery();

                if (FileLink != null)
                {
                    dataRow[Constants.SOProperties.LinkToItem] = FileLink.Value;
                    results.Rows.Add(dataRow);
                }
            }
        }
        private void ExecuteRemoveItemPermissionById()
        {
            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            string listTitle   = serviceObject.GetListTitle();
            string siteURL     = GetSiteURL();
            int    id          = base.GetIntProperty(Constants.SOProperties.ID, true);
            string userLogins  = base.GetStringProperty(Constants.SOProperties.UserLogins);
            string groupLogins = base.GetStringProperty(Constants.SOProperties.GroupLogins);

            if (string.IsNullOrEmpty(userLogins) && string.IsNullOrEmpty(groupLogins))
            {
                throw new ApplicationException(Constants.ErrorMessages.UserGroupLoginsAreEmptyException);
            }

            using (ClientContext context = InitializeContext(siteURL))
            {
                Web spWeb = context.Web;

                List     list     = spWeb.Lists.GetByTitle(listTitle);
                ListItem listItem = list.GetItemById(id);
                context.Load(listItem);
                context.ExecuteQuery();

                RoleAssignmentCollection roles = listItem.RoleAssignments;
                context.Load(roles, role => role.Include(roleassigned => roleassigned.Member.LoginName, roleassigned => roleassigned.Member));
                context.ExecuteQuery();

                if (!string.IsNullOrEmpty(userLogins))
                {
                    foreach (User user in GetUsersByLoginString(context, userLogins))
                    {
                        context.Load(user, u => u.LoginName);
                        context.ExecuteQuery();

                        foreach (RoleAssignment role in roles)
                        {
                            if (role.Member.LoginName == user.LoginName)
                            {
                                role.DeleteObject();
                                break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(groupLogins))
                {
                    foreach (Group group in GetGroupsByLoginString(context, groupLogins))
                    {
                        context.Load(group, g => g.LoginName);
                        context.ExecuteQuery();

                        foreach (RoleAssignment role in roles)
                        {
                            if (role.Member.LoginName == group.LoginName)
                            {
                                role.DeleteObject();
                                break;
                            }
                        }
                    }
                }

                context.ExecuteQuery();
            }
        }