public int CreateWebPartPage(ClientContext clientContext, string pageName, string layout, string masterpagelistName, string listName, string pageTitle) { int response = -1; if (null != clientContext && !string.IsNullOrWhiteSpace(pageName) && !string.IsNullOrWhiteSpace(layout) && !string.IsNullOrWhiteSpace(masterpagelistName) && !string.IsNullOrWhiteSpace(listName)) { try { //// Find Default Layout from Master Page Gallery to create Web Part Page Microsoft.SharePoint.Client.Web web = clientContext.Web; ListItemCollection collection = spList.GetData(clientContext, masterpagelistName); clientContext.Load(collection, listItemCollectionProperties => listItemCollectionProperties.Include(listItemProperties => listItemProperties.Id, listItemProperties => listItemProperties.DisplayName)); clientContext.ExecuteQuery(); ListItem fileName = null; foreach (ListItem findLayout in collection) { if (findLayout.DisplayName.Equals(layout, StringComparison.OrdinalIgnoreCase)) { fileName = findLayout; break; } } FileCreationInformation objFileInfo = new FileCreationInformation(); objFileInfo.Url = pageName; Microsoft.SharePoint.Client.File fileLayout = fileName.File; clientContext.Load(fileLayout); clientContext.ExecuteQuery(); ClientResult <Stream> filedata = fileLayout.OpenBinaryStream(); List sitePageLib = web.Lists.GetByTitle(listName); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); StreamReader reader = new StreamReader(filedata.Value); objFileInfo.Content = System.Text.Encoding.ASCII.GetBytes(reader.ReadToEnd()); Microsoft.SharePoint.Client.File matterLandingPage = sitePageLib.RootFolder.Files.Add(objFileInfo); ListItem matterLandingPageDetails = matterLandingPage.ListItemAllFields; // Update the title of the page matterLandingPageDetails[ServiceConstants.TITLE] = pageTitle; matterLandingPageDetails.Update(); clientContext.Load(matterLandingPageDetails, matterLandingPageProperties => matterLandingPageProperties[ServiceConstants.TITLE], matterLandingPageProperties => matterLandingPageProperties.Id); clientContext.ExecuteQuery(); response = matterLandingPageDetails.Id; } catch (Exception) { response = -1; } } return(response); }
/// <summary> /// Thios method will get all roles such as attorney journal etc which are configured in the catalog site collection /// </summary> /// <param name="client"></param> /// <returns>async Task<IList<Role>></returns> public async Task <IList <Role> > GetRolesAsync(Client client) { IList <Role> roles = new List <Role>(); ListItemCollection collListItem = await Task.FromResult(spList.GetData(client, listNames.DMSRoleListName, camlQueries.DMSRoleQuery)); if (null != collListItem && 0 != collListItem.Count) { foreach (ListItem item in collListItem) { Role tempRole = new Role(); tempRole.Id = Convert.ToString(item[matterSettings.ColumnNameGuid], CultureInfo.InvariantCulture); tempRole.Name = Convert.ToString(item[matterSettings.RoleListColumnRoleName], CultureInfo.InvariantCulture); tempRole.Mandatory = Convert.ToBoolean(item[matterSettings.RoleListColumnIsRoleMandatory], CultureInfo.InvariantCulture); roles.Add(tempRole); } } return(roles); }
public DuplicateDocument DocumentExists(ClientContext clientContext, ContentCheckDetails contentCheck, string documentLibraryName, string folderPath, bool isMail) { DuplicateDocument duplicateDocument = new DuplicateDocument(false, false); if (null != clientContext && null != contentCheck && !string.IsNullOrEmpty(documentLibraryName) && !string.IsNullOrEmpty(folderPath)) { string serverRelativePath = folderPath + ServiceConstants.FORWARD_SLASH + contentCheck.FileName; string camlQuery = string.Format(CultureInfo.InvariantCulture, camlQueries.GetAllFilesInFolderQuery, serverRelativePath); ListItemCollection listItemCollection = null; listItemCollection = spList.GetData(clientContext, documentLibraryName, camlQuery); duplicateDocument.DocumentExists = (null != listItemCollection && 0 < listItemCollection.Count) ? true : false; // Check file size, from, sent date as well. if (duplicateDocument.DocumentExists) { // check for other conditions as well. ListItem listItem = listItemCollection.FirstOrDefault(); DateTime sentDate, storedFileSentDate; long fileSize = Convert.ToInt64(listItem.FieldValues[mailSettings.SearchEmailFileSize], CultureInfo.InvariantCulture); if (isMail) { // check for subject, from and sent date string subject = Convert.ToString(listItem.FieldValues[mailSettings.SearchEmailSubject], CultureInfo.InvariantCulture); string from = Convert.ToString(listItem.FieldValues[mailSettings.SearchEmailFrom], CultureInfo.InvariantCulture); bool isValidDateFormat; isValidDateFormat = DateTime.TryParse(Convert.ToString(listItem.FieldValues[mailSettings.SearchEmailSentDate], CultureInfo.InvariantCulture), out storedFileSentDate); isValidDateFormat &= DateTime.TryParse(contentCheck.SentDate, out sentDate); if (isValidDateFormat) { TimeSpan diffrence = sentDate - storedFileSentDate; uint tolleranceMin = Convert.ToUInt16(mailSettings.SentDateTolerance, CultureInfo.InvariantCulture); // up to how much minutes difference between uploaded files is tolerable duplicateDocument.HasPotentialDuplicate = ((fileSize == contentCheck.FileSize) && (subject.Trim() == contentCheck.Subject.Trim()) && (from.Trim() == contentCheck.FromField.Trim()) && (diffrence.Minutes < tolleranceMin)); } } else { duplicateDocument.HasPotentialDuplicate = (fileSize == contentCheck.FileSize); } } } return(duplicateDocument); }