public void CheckIn(string url, Guid libraryId, int itemId, FileCheckInOptions options) { try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var spfile = clientContext.Web.Lists.GetById(libraryId).GetItemById(itemId).File; var type = !string.IsNullOrEmpty(options.CheckinType) ? (CheckinType)Enum.Parse(typeof(CheckinType), options.CheckinType) : CheckinType.MajorCheckIn; spfile.CheckIn(options.Comment, type); if (options.KeepCheckOut) { spfile.CheckOut(); } clientContext.ExecuteQuery(); } } catch (Exception ex) { var message = string.Format("An exception of type {0} occurred in the InternalApi.SPFileService.CheckIn() method for URL: {1}, LibraryId: {2}, ItemId: {3}. The exception message is: {4}", ex.GetType(), url, libraryId, itemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message); } }
public void Restore(string url, Guid libraryId, int itemId, string version) { try { var auth = credentials.Get(url); using (var clientContext = new SPContext(url, auth)) { var spfile = clientContext.Web.Lists.GetById(libraryId).GetItemById(itemId).File; clientContext.Load(spfile, f => f.ServerRelativeUrl); clientContext.ExecuteQuery(); var fileName = spfile.ServerRelativeUrl; // There is no way to restore file using Client Object Model using (var service = new VersionService(url, auth)) { service.RestoreVersion(fileName, version); } } } catch (Exception ex) { var message = string.Format("An exception of type {0} occurred in the InternalApi.SPFileService.Restore() method for URL: {1}, LibraryId: {2}, ItemId: {3}, Version: {4}. The exception message is: {5}", ex.GetType(), url, libraryId, itemId, version, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message); } }
public void AddUserToGroup(string url, Authentication authentication, string loginNames, int groupId) { // Group Id is invalid if (groupId <= 0) { return; } using (var clientContext = new SPContext(url, authentication ?? credentials.Get(url))) { var group = clientContext.Web.SiteGroups.GetById(groupId); foreach (var loginName in loginNames.Split(',')) { var user = clientContext.Web.EnsureUser(loginName); group.Users.AddUser(user); } try { clientContext.ExecuteQuery(); } catch (ServerException ex) { //User not found SPLog.RoleOperationUnavailable(ex, String.Format("A server exception occurred while adding users to the group with id '{0}'. The exception message is: {1}", groupId, ex.Message)); } } }
public void ResetInheritance(PermissionsGetQuery options) { var spwebUrl = EnsureUrl(options.Url, options.ListId); try { using (var clientContext = new SPContext(spwebUrl, credentials.Get(spwebUrl))) { List splist = clientContext.Web.Lists.GetById(options.ListId); var splistItemCollection = splist.GetItems(options.Id.HasValue ? CAMLQueryBuilder.GetItem(options.Id.Value, new string[] { }) : CAMLQueryBuilder.GetItem(options.ContentId, new string[] { })); var lazyListItems = clientContext.LoadQuery(splistItemCollection.Include(item => item.HasUniqueRoleAssignments, item => item.Id)); clientContext.ExecuteQuery(); var splistItem = lazyListItems.First(); splistItem.ResetRoleInheritance(); clientContext.ExecuteQuery(); } } catch (Exception ex) { string itemId = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString(); string message = string.Format("An exception of type {0} occurred in the SPPermissionsService.ResetInheritance() method for ListId: {1} ItemId: {2}. The exception message is: {3}", ex.GetType(), options.ListId, itemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } }
public PagedList <SPList> ListItemsToReindex(Guid typeId, int batchSize, string[] viewFields = null) { var lists = listDataService.ListsToReindex(typeId, batchSize); var spLists = new PagedList <SPList> { PageSize = lists.PageSize, PageIndex = lists.PageIndex, TotalCount = lists.TotalCount }; foreach (var list in lists) { try { var splist = Get(new ListGetQuery(list.Id, typeId)); if (splist != null) { spLists.Add(splist); } } catch (SPInternalException) { } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.ListsToReindex() method for ApplicationTypeId: {1} BatchSize: {2}. The exception message is: {3}", ex.GetType(), typeId, batchSize, ex.Message); SPLog.RoleOperationUnavailable(ex, message); } } return(spLists); }
public List <Folder> List(string url, Guid libraryId, string folderPath) { var folderList = new List <Folder>(); try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var list = clientContext.Web.Lists.GetById(libraryId); var rootFolder = list.RootFolder; clientContext.Load(rootFolder, f => f.ServerRelativeUrl); var spfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath); var folderCollection = clientContext.LoadQuery(SP.ClientObjectQueryableExtension.Include(spfolder.Folders, f => f.Name, f => f.ServerRelativeUrl, f => f.ItemCount)); clientContext.ExecuteQuery(); folderList.AddRange(from f in folderCollection where !IsHiddenFolder(f.ServerRelativeUrl, rootFolder.ServerRelativeUrl) select new Folder(f.Name, f.ServerRelativeUrl, f.ItemCount, libraryId)); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPFolderService.List() method LibraryId: {1} ServerRelativeUrl: '{2}' SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), libraryId, folderPath, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(folderList); }
public void Delete(Guid id, bool deleteList) { var list = listDataService.Get(id); if (list == null) { return; } Validate(list); listDataService.Delete(list.Id); if (deleteList) { try { using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { var splist = clientContext.Web.Lists.GetById(list.Id); splist.DeleteObject(); clientContext.ExecuteQuery(); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.Delete() method for ApplicationId: {1}. The exception message is: {2}", ex.GetType(), id, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } } }
public bool CanEdit(Guid listId) { var listBase = listDataService.Get(listId); if (listBase == null) { return(false); } Validate(listBase); try { bool?canEdit; using (var spcontext = new SPContext(listBase.SPWebUrl, credentials.Get(listBase.SPWebUrl))) { var splist = spcontext.Web.Lists.GetById(listId); spcontext.Load(splist, l => l.EffectiveBasePermissions); spcontext.ExecuteQuery(); canEdit = splist.EffectiveBasePermissions.Has(PermissionKind.EditListItems); } return(canEdit.Value); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.CanEdit() method for ApplicationId: {1}. The exception message is: {2}", ex.GetType(), listId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } }
public List <SPPermissionsLevel> Levels(string webUrl) { var levels = new List <SPPermissionsLevel>(); try { using (var clientContext = new SPContext(webUrl, credentials.Get(webUrl))) { var web = clientContext.Web; clientContext.Load(web, w => w.RoleDefinitions.Include( rd => rd.Id, rd => rd.Name, rd => rd.Description)); clientContext.ExecuteQuery(); foreach (var rd in web.RoleDefinitions) { levels.Add(new SPPermissionsLevel(rd.Id, rd.Name) { Description = rd.Description }); } } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the SPPermissionsService.Levels() method for SPWebUrl: {1}. The exception message is: {2}", ex.GetType(), webUrl, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(levels); }
public SPPermissions Get(int userOrGroupId, PermissionsGetQuery options) { var spwebUrl = EnsureUrl(options.Url, options.ListId); try { using (var clientContext = new SPContext(spwebUrl, credentials.Get(spwebUrl))) { List splist = clientContext.Web.Lists.GetById(options.ListId); var splistItemCollection = splist.GetItems(options.Id.HasValue ? CAMLQueryBuilder.GetItem(options.Id.Value, new string[] { }) : CAMLQueryBuilder.GetItem(options.ContentId, new string[] { })); var listItemRoleAssignments = clientContext.LoadQuery( splistItemCollection.Select(item => item.RoleAssignments.GetByPrincipalId(userOrGroupId)).Include( roleAssignment => roleAssignment.Member, roleAssignment => roleAssignment.RoleDefinitionBindings.Include( roleDef => roleDef.Id, roleDef => roleDef.Name, roleDef => roleDef.Description))); clientContext.ExecuteQuery(); return(listItemRoleAssignments.First().ToPermission()); } } catch (Exception ex) { string itemId = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString(); string message = string.Format("An exception of type {0} occurred in the SPPermissionsService.Get() method for a User or Group with Id: {1} ListId: {2} ItemId: {3}. The exception message is: {4}", ex.GetType(), userOrGroupId, options.ListId, itemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } }
public Folder Get(string url, Guid libraryId, string folderPath) { Folder folder; try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var spfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath); clientContext.Load(spfolder, f => f.Name, f => f.ServerRelativeUrl, f => f.ItemCount); clientContext.ExecuteQuery(); folder = new Folder(spfolder.Name, spfolder.ServerRelativeUrl, spfolder.ItemCount, libraryId); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPFolderService.Get() method LibraryId: {1} ServerRelativeUrl: '{2}' SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), libraryId, folderPath, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(folder); }
public SPUser Get(string url, string name) { using (var clientContext = new SPContext(url, credentials.Get(url))) { SP.Web web = clientContext.Web; // find users with equal account names SP.ListItemCollection usersByEqualQuery = web.SiteUserInfoList.GetItems(new SP.CamlQuery { ViewXml = ViewQueryWhere(EqualQuery("Name", name, "Text")) }); IEnumerable <SP.ListItem> userItemsByEqualQuery = clientContext.LoadQuery(SP.ClientObjectQueryableExtension.Include(usersByEqualQuery, SPUser.InstanceQuery)); // find users with the same account names SP.ListItemCollection usersByContainsQuery = web.SiteUserInfoList.GetItems(new SP.CamlQuery { ViewXml = ViewQueryWhere(ContainsQuery("Name", name, "Text")) }); IEnumerable <SP.ListItem> userItemsByContainsQuery = clientContext.LoadQuery(SP.ClientObjectQueryableExtension.Include(usersByContainsQuery, SPUser.InstanceQuery)); // find users by display name SP.ListItemCollection usersByTitleQuery = web.SiteUserInfoList.GetItems(new SP.CamlQuery { ViewXml = ViewQueryWhere(EqualQuery("Title", name, "Text")) }); IEnumerable <SP.ListItem> userItemsByTitleQuery = clientContext.LoadQuery(SP.ClientObjectQueryableExtension.Include(usersByTitleQuery, SPUser.InstanceQuery)); try { clientContext.ExecuteQuery(); } catch (SP.ServerException ex) { SPLog.RoleOperationUnavailable(ex, String.Format("A server exception occurred while getting the user with name {0}'. The exception message is: {1}", name, ex.Message)); return(null); } SPUser user = TryGet(userItemsByEqualQuery); if (user != null) { return(user); } user = TryGet(userItemsByContainsQuery); if (user != null) { return(user); } user = TryGet(userItemsByTitleQuery); if (user != null) { return(user); } return(null); } }
public IRestResponse Get(SPViewItemRequest request) { var response = new DefaultRestResponse { Name = "View" }; var errors = new List <string>(); ValidateUrl(request.Url, errors); var listId = ValidateListId(request.ListId, errors); var viewId = ValidateViewId(request.ViewId, errors); if (errors.Any()) { response.Errors = errors.ToArray(); return(response); } response.Data = cacheService.Get(CacheKey(listId, viewId, request.Url), CacheScope.Context | CacheScope.Process); if (response.Data == null) { try { using (var clientContext = new SPContext(request.Url, IntegrationManagerPlugin.CurrentAuth(request.Url), runAsServiceAccount: true)) { var site = clientContext.Site; clientContext.Load(site, s => s.Id); var web = clientContext.Web; clientContext.Load(web, w => w.Id); var list = clientContext.Web.Lists.GetById(listId); var view = list.GetView(viewId); clientContext.Load(view, RestSPView.InstanceQuery); clientContext.ExecuteQuery(); response.Data = new SPViewItemData { Item = new RestSPView(view), SiteId = site.Id, WebId = web.Id }; } cacheService.Put(CacheKey(listId, viewId, request.Url), response.Data, CacheScope.Context | CacheScope.Process, new string[] { }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.Views.Get() method for ListId: {1} ViewId: {2} SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), listId, viewId, request.Url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } return(response); }
public void UpdateIndexingStatus(Guid[] contentIds, bool isIndexed) { try { listDataService.UpdateIndexingStatus(contentIds, isIndexed); } catch (Exception ex) { var ids = contentIds != null && contentIds.Length > 0 ? string.Join(", ", contentIds) : string.Empty; string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.UpdateIndexingStatus() method for ContentIds: {1} IsIndexed: {2}. The exception message is: {3}", ex.GetType(), ids, isIndexed, ex.Message); SPLog.RoleOperationUnavailable(ex, message); } }
public IEnumerable <SPUser> GetValues(string url, string listId, int listItemId, string internalName, bool allowMultipleValues) { object value = PublicApi.ListItems.Get(Guid.Parse(listId), new SPListItemGetOptions(listItemId) { Url = url }).Value(internalName); if (value != null) { List <SP.FieldUserValue> valueList = allowMultipleValues ? ((SP.FieldUserValue[])value).ToList() : new List <SP.FieldUserValue> { (SP.FieldUserValue)value }; var userList = valueList.Select(userValue => new SPUser(userValue.LookupId)).ToList(); using (var clientContext = new SPContext(url, credentials.Get(url))) { SP.Web web = clientContext.Web; SP.ListItemCollection users = web.SiteUserInfoList.GetItems(new SP.CamlQuery { ViewXml = CamlQueryBuilder(userList.Select(user => user.LookupId), "ID", "Counter") }); IEnumerable <SP.ListItem> userListItems = clientContext.LoadQuery(SP.ClientObjectQueryableExtension.Include(users, SPUser.InstanceQuery)); try { clientContext.ExecuteQuery(); } catch (SP.ServerException ex) { SPLog.RoleOperationUnavailable(ex, string.Format("A server exception occurred while getting users from '{0}' field. The exception message is: {1}", internalName, ex.Message)); return(null); } Dictionary <int, SP.ListItem> userHash = userListItems.ToDictionary(item => item.Id); foreach (SPUser user in userList) { if (userHash.ContainsKey(user.LookupId)) { user.Initialize(userHash[user.LookupId]); } } return(userList); } } return(Enumerable.Empty <SPUser>()); }
internal static SPConfiguration Get(string url, Authentication auth) { var config = new SPConfiguration(url, auth); using (var spcontext = new SPContext(url, auth)) { try { SP.Web web = spcontext.Site.RootWeb; var siteProfileFieldsQuery = spcontext.LoadQuery(web.SiteUserInfoList.Fields).Where(f => !f.Hidden); spcontext.ExecuteQuery(); config.SiteProfileFields = siteProfileFieldsQuery.Select(f => new ProfileField(f.StaticName, f.Title, !f.ReadOnlyField)).OrderBy(f => f.Title).ToList(); spcontext.Load(web.AllProperties, prop => prop[SPWebPropertyKey.SyncEnabled], prop => prop[SPWebPropertyKey.SiteSettings], prop => prop[SPWebPropertyKey.FarmSettings], prop => prop[SPWebPropertyKey.FarmSyncEnabled]); spcontext.ExecuteQuery(); ParseWebProperties(web, config); } catch (Exception) { SPLog.Info("Profile Sync properites do not exist in SharePoint. These are optional fields, no action is required."); } } config.FarmProfileFields = new List <ProfileField>(); using (var userProfileService = new ProfileService(url, auth)) { try { var properties = userProfileService.GetUserProfileSchema(); foreach (var property in properties.OrderBy(p => p.DisplayName)) { config.FarmProfileFields.Add(new ProfileField(property.Name, property.DisplayName, property.IsUserEditable)); } } catch (Exception ex) { SPLog.RoleOperationUnavailable(ex, ex.Message); } } return(config); }
public List <User> List(ref int nextIndex) { try { SP.Web web = spcontext.Site.RootWeb; // Set up pageSize (pageIndex == 0 by default) CamlQuery paginationQuery = CamlQuery.CreateAllItemsQuery(userProfileBatchCapacity); // Load position to update pagination query int currentItemCounterIndex = userProfileBatchCapacity * nextIndex; if (currentItemCounterIndex > 0) { CamlQuery query = CamlQuery.CreateAllItemsQuery(currentItemCounterIndex); ListItemCollection emptySPUserCollection = web.SiteUserInfoList.GetItems(query); spcontext.Load(emptySPUserCollection, items => items.ListItemCollectionPosition); spcontext.ExecuteQuery(); // Set up pageIndex paginationQuery.ListItemCollectionPosition = emptySPUserCollection.ListItemCollectionPosition; if (emptySPUserCollection.ListItemCollectionPosition == null) { return(new List <User>()); } } // Load user profiles ListItemCollection spuserCollection = web.SiteUserInfoList.GetItems(paginationQuery); spcontext.Load(spuserCollection); spcontext.ExecuteQuery(); var dataUserList = new List <User>(); InitUserList(spuserCollection, dataUserList); return(dataUserList); } catch (Exception ex) { SPLog.RoleOperationUnavailable(ex, ex.Message); } finally { nextIndex++; } return(new List <User>()); }
public Folder Delete(string url, Guid libraryId, string folderPath) { Folder folder; try { using (var clientContext = new SPContext(url, credentials.Get(url))) { SP.List splist = clientContext.Web.Lists.GetById(libraryId); SP.Folder rootFolder = splist.RootFolder; clientContext.Load(rootFolder, f => f.ServerRelativeUrl); SP.Folder spfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath); clientContext.Load(spfolder, f => f.Name, f => f.ServerRelativeUrl, f => f.ItemCount); clientContext.ExecuteQuery(); bool pathIsNotEmpty = !String.IsNullOrEmpty(spfolder.ServerRelativeUrl.Trim('/')); bool isARootFolder = rootFolder.ServerRelativeUrl.Trim('/').Equals(spfolder.ServerRelativeUrl.Trim('/')); bool hasParentFolder = pathIsNotEmpty && !isARootFolder; if (hasParentFolder && !IsHiddenFolder(spfolder.ServerRelativeUrl, rootFolder.ServerRelativeUrl)) { folder = new Folder(spfolder.Name, spfolder.ServerRelativeUrl, spfolder.ItemCount, libraryId); spfolder.DeleteObject(); clientContext.ExecuteQuery(); } else { throw new SPInternalException("Folder can not be removed."); } } } catch (SPInternalException) { throw; } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPFolderService.Delete() method LibraryId: {1} ServerRelativeUrl: '{2}' in SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), libraryId, folderPath, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(folder); }
public SPList Create(int templateType, ListCreateQuery options) { Validate(options); SPList list; try { using (var clientContext = new SPContext(options.SPWebUrl, credentials.Get(options.SPWebUrl))) { var site = clientContext.Site; clientContext.Load(site, s => s.Id); var listCreationInformation = new ListCreationInformation { Title = options.Title, Description = options.Description, TemplateType = templateType }; var splist = clientContext.Web.Lists.Add(listCreationInformation); clientContext.Load(splist, InstanceQuery); clientContext.ExecuteQuery(); list = new SPList(splist, site.Id) { GroupId = options.GroupId }; Add(new ListBase(list.GroupId, list.Id, options.TypeId, options.SPWebUrl) { ApplicationKey = list.Title }); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.Create() method. The exception message is: {1}", ex.GetType(), ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(list); }
public List <Folder> UpToParent(string url, Guid libraryId, string folderPath) { var folderList = new List <Folder>(); try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var list = clientContext.Web.Lists.GetById(libraryId); var rootFolder = list.RootFolder; clientContext.Load(rootFolder, f => f.Name, f => f.ServerRelativeUrl, f => f.ItemCount); clientContext.ExecuteQuery(); bool pathIsNotEmpty = !String.IsNullOrEmpty(folderPath.Trim('/')); bool isARootFolder = rootFolder.ServerRelativeUrl.Trim('/').Equals(folderPath.Trim('/')); bool hasParentFolder = pathIsNotEmpty && !isARootFolder; while (hasParentFolder) { var spfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath); clientContext.Load(spfolder, f => f.Name, f => f.ServerRelativeUrl, f => f.ItemCount); clientContext.Load(spfolder.ParentFolder, p => p.ServerRelativeUrl); clientContext.ExecuteQuery(); folderList.Add(new Folder(spfolder.Name, spfolder.ServerRelativeUrl, spfolder.ItemCount, libraryId)); folderPath = spfolder.ParentFolder.ServerRelativeUrl; pathIsNotEmpty = !String.IsNullOrEmpty(folderPath.Trim('/')); isARootFolder = rootFolder.ServerRelativeUrl.Trim('/').Equals(folderPath.Trim('/')); hasParentFolder = pathIsNotEmpty && !isARootFolder; } folderList.Add(new Folder(rootFolder.Name, rootFolder.ServerRelativeUrl, rootFolder.ItemCount, libraryId)); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPFolderService.UpToParent() method LibraryId: {1} ServerRelativeUrl: '{2}' SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), libraryId, folderPath, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } return(folderList); }
public SPUser Get(string url, int lookupId) { using (var clientContext = new SPContext(url, credentials.Get(url))) { try { var userProfile = clientContext.Web.SiteUserInfoList.GetItemById(lookupId); clientContext.Load(userProfile, SPUser.InstanceQuery); clientContext.ExecuteQuery(); return(new SPUser(userProfile)); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.UserProfileService.Get() method URL: {1}, LookupId: {2}. The exception message is: {4}", ex.GetType(), url, lookupId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); } } return(null); }
public void CheckOut(string url, Guid libraryId, int itemId) { try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var spfile = clientContext.Web.Lists.GetById(libraryId).GetItemById(itemId).File; spfile.CheckOut(); clientContext.ExecuteQuery(); } } catch (Exception ex) { var message = string.Format("An exception of type {0} occurred in the InternalApi.SPFileService.CheckOut() method for URL: {1}, LibraryId: {2}, ItemId: {3}. The exception message is: {4}", ex.GetType(), url, libraryId, itemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message); } }
protected void ApplyBtnClick(object sender, EventArgs e) { if (!Page.IsValid) { ShowErrorMessage("Invalid Data"); return; } try { spConfig.SyncEnabled = cbSyncEnable.Checked; spConfig.FarmSyncEnabled = cbFarmSyncEnable.Checked; spConfig.SiteProfileMappedFields = new List <UserFieldMapping>(); ProcessPostedData(spConfig.SiteProfileMappedFields, hdnSiteProfileFieldsMap.Value); spConfig.FarmProfileMappedFields = new List <UserFieldMapping>(); ProcessPostedData(spConfig.FarmProfileMappedFields, hdnFarmProfileFieldsMap.Value); // Save Configuration to a syncSettings object spSyncSettings.SyncConfig = new SPBaseConfig { FarmProfileMappedFields = spConfig.FarmProfileMappedFields, SiteProfileMappedFields = spConfig.SiteProfileMappedFields, SyncEnabled = spConfig.SyncEnabled, FarmSyncEnabled = spConfig.FarmSyncEnabled }; BindDropDownListData(ddlSPSiteProfileFields, spConfig.SiteProfileFields.OrderBy(f => f.Title).ToList(), f => String.Format("{0} - {1}", f.Title, f.Name)); BindDropDownListData(ddlSPFarmProfileFields, spConfig.FarmProfileFields.OrderBy(f => f.Title), f => f.Title); BindDropDownListData(ddlTEProfileFields, TEUserProfileFieldsHelper.GetFields().OrderBy(f => f.Name).ToList(), f => f.Name); const string script = @"setTimeout(function(){{parent.window.frames[0].AddSyncSettings('{0}');}},100);"; CSControlUtility.Instance().RegisterClientScriptBlock(this, GetType(), "applychildwindow", string.Format(script, JavaScript.Encode(spSyncSettings.ToXml())), true); } catch (Exception ex) { ShowErrorMessage(ex.Message); SPLog.RoleOperationUnavailable(ex, ex.Message); } }
protected void SaveBtnClick(object sender, EventArgs e) { if (!Page.IsValid) { ShowErrorMessage("Invalid Data"); return; } try { spConfig.SyncEnabled = cbSyncEnable.Checked; spConfig.FarmSyncEnabled = cbFarmSyncEnable.Checked; spConfig.SiteProfileMappedFields = new List <UserFieldMapping>(); ProcessPostedData(spConfig.SiteProfileMappedFields, hdnSiteProfileFieldsMap.Value); spConfig.FarmProfileMappedFields = new List <UserFieldMapping>(); ProcessPostedData(spConfig.FarmProfileMappedFields, hdnFarmProfileFieldsMap.Value); // Save Configuration to a syncSettings object spSyncSettings.SyncConfig = new SPBaseConfig { FarmProfileMappedFields = spConfig.FarmProfileMappedFields, SiteProfileMappedFields = spConfig.SiteProfileMappedFields, SyncEnabled = spConfig.SyncEnabled, FarmSyncEnabled = spConfig.FarmSyncEnabled }; const string script = @"setTimeout(function(){{CloseWindow('{0}');}},100);"; CSControlUtility.Instance().RegisterClientScriptBlock(this, GetType(), "closechildwindow", string.Format(script, JavaScript.Encode(spSyncSettings.ToXml())), true); TempStoreSPSyncSettingsList(true); } catch (Exception ex) { ShowErrorMessage(ex.Message); SPLog.RoleOperationUnavailable(ex, ex.Message); } }
/// <summary> /// Recycle Folder /// </summary> /// <param name="url">SPWeb Url</param> /// <param name="folderPath"></param> /// <returns>A Guid that represents the transaction ID of the delete transaction.</returns> public Guid Recycle(string url, string folderPath) { try { using (var clientContext = new SPContext(url, credentials.Get(url))) { var spfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderPath); var removedItems = spfolder.Recycle(); clientContext.ExecuteQuery(); return(removedItems.Value); } } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPFolderService.Recycle() method ServerRelativeUrl: '{1}' in SPWebUrl: '{2}'. The exception message is: {3}", ex.GetType(), folderPath, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } }
public PagedList <SPPermissions> List(PermissionsListQuery options) { var spwebUrl = EnsureUrl(options.Url, options.ListId); try { using (var clientContext = new SPContext(spwebUrl, credentials.Get(spwebUrl))) { List splist = clientContext.Web.Lists.GetById(options.ListId); var splistItemCollection = splist.GetItems(options.Id.HasValue ? CAMLQueryBuilder.GetItem(options.Id.Value, new string[] { }) : CAMLQueryBuilder.GetItem(options.ContentId, new string[] { })); var lazyListItems = clientContext.LoadQuery(splistItemCollection.Include(item => item.HasUniqueRoleAssignments, item => item.Id)); clientContext.ExecuteQuery(); var splistItem = lazyListItems.First(); IEnumerable <RoleAssignment> lazyRoleAssignmentList = RoleAssignmentsLoadQuery(splistItem, clientContext); clientContext.ExecuteQuery(); var roleAssignmentList = lazyRoleAssignmentList.ToList(); return(new PagedList <SPPermissions>(roleAssignmentList.Skip(options.PageSize * options.PageIndex).Take(options.PageSize).Select(ra => ra.ToPermission())) { PageSize = options.PageSize, PageIndex = options.PageIndex, TotalCount = roleAssignmentList.Count }); } } catch (Exception ex) { string listItemId = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString(); string message = string.Format("An exception of type {0} occurred in the SPPermissionsService.List() method for ListId: {1} ItemId: {2}. The exception message is: {3}", ex.GetType(), options.ListId, listItemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } }
public void Remove(int[] userOrGroupIds, PermissionsGetQuery options) { if (userOrGroupIds != null && userOrGroupIds.Length > 0) { var spwebUrl = EnsureUrl(options.Url, options.ListId); try { using (var clientContext = new SPContext(spwebUrl, credentials.Get(spwebUrl))) { List splist = clientContext.Web.Lists.GetById(options.ListId); var splistItemCollection = splist.GetItems(options.Id.HasValue ? CAMLQueryBuilder.GetItem(options.Id.Value, new string[] { }) : CAMLQueryBuilder.GetItem(options.ContentId, new string[] { })); var lazyListItems = clientContext.LoadQuery(splistItemCollection.Include(item => item.HasUniqueRoleAssignments, item => item.Id)); clientContext.ExecuteQuery(); var splistItem = lazyListItems.First(); foreach (int userOrGroupId in userOrGroupIds) { splistItem.RoleAssignments.GetByPrincipalId(userOrGroupId).DeleteObject(); } clientContext.ExecuteQuery(); } } catch (Exception ex) { string listItemId = options.Id.HasValue ? options.Id.Value.ToString(CultureInfo.InvariantCulture) : options.ContentId.ToString(); string userOrGroupIdsString = string.Join(", ", userOrGroupIds); string message = string.Format("An exception of type {0} occurred in the SPPermissionsService.Remove() method for Users or Groups with Ids: {1} ListId: {2} ItemId: {3}. The exception message is: {4}", ex.GetType(), userOrGroupIdsString, options.ListId, listItemId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } } }
public PagedList <Library> List(int groupId, LibraryListOptions options) { var libraries = (List <Library>)cacheService.Get(CacheKey(groupId), CacheScope.Context | CacheScope.Process); if (libraries == null) { libraries = new List <Library>(); var lists = listService.List(groupId, options); try { libraries.AddRange(lists.Select(list => new Library(list))); cacheService.Put(CacheKey(groupId), libraries, CacheScope.Context | CacheScope.Process, new[] { Tag(groupId) }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the PublicApi.Libraries.List() method for GroupId: {1}. The exception message is: {2}", ex.GetType(), groupId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); throw new SPInternalException(message, ex); } } if (!String.IsNullOrEmpty(options.Filter)) { libraries = libraries.Where(library => library.Name.Contains(options.Filter, StringComparison.InvariantCultureIgnoreCase)).ToList(); } Library.SortBy sortBy; Enum.TryParse(options.SortBy, out sortBy); return(new PagedList <Library>(libraries.Order(sortBy, options.SortOrder).Skip(options.PageSize * options.PageIndex).Take(options.PageSize)) { PageSize = options.PageSize, PageIndex = options.PageIndex, TotalCount = libraries.Count }); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { try { // Data Binding cbSyncEnable.Checked = spConfig.SyncEnabled; cbFarmSyncEnable.Checked = spConfig.FarmSyncEnabled; BindDropDownListData(ddlSPSiteProfileFields, spConfig.SiteProfileFields.OrderBy(f => f.Title).ToList(), f => f.Title); BindDropDownListData(ddlSPFarmProfileFields, spConfig.FarmProfileFields.OrderBy(f => f.Title), f => f.Title); BindDropDownListData(ddlTEProfileFields, TEUserProfileFieldsHelper.GetFields().OrderBy(f => f.Name).ToList(), f => f.Title); hdnSiteProfileFieldsMap.Value = GetJSONMapping(spConfig.SiteProfileMappedFields); hdnFarmProfileFieldsMap.Value = GetJSONMapping(spConfig.FarmProfileMappedFields); } catch (Exception ex) { ShowErrorMessage(ex.Message); SPLog.RoleOperationUnavailable(ex, ex.Message); } } }
public List <SPList> List(int groupId, ListQuery options) { var lists = new List <SPList>(); var listBases = listDataService.List(groupId, options.TypeId); foreach (var listBase in listBases) { try { var list = Get(new ListGetQuery(listBase.Id, listBase.TypeId)); if (list != null) { lists.Add(list); } } catch (SPInternalException) { } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the InternalApi.SPListService.List() method for GroupId: {1}. The exception message is: {2}", ex.GetType(), groupId, ex.Message); SPLog.RoleOperationUnavailable(ex, message); } } return(lists); }