/// <summary> /// Sends individual document to OneDrive /// </summary> /// <param name="clientContext">SP client context</param> /// <param name="collectionOfAttachments">Dictionary object containing attachment URLs and their stream data</param> /// <param name="listItemsColl">List item collection of Legal Briefcase folder</param> /// <param name="allAttachmentUrl">A string array containing all the attachment URLs</param> /// <param name="web">Object of site</param> /// <param name="usersMySite">My Site URL of the user</param> /// <param name="collectionOfOriginalAttachments">Dictionary object containing attachment URLs</param> /// <param name="defaultContentTypeId">Default content type Id</param> /// <param name="status">Status of documents sent to OneDrive</param> /// <returns>Status of documents sent to OneDrive</returns> internal static string SendIndividualDocument(ClientContext clientContext, Dictionary <string, Stream> collectionOfAttachments, ListItemCollection listItemsColl, string[] allAttachmentUrl, Microsoft.SharePoint.Client.Web web, string usersMySite, Dictionary <string, string> collectionOfOriginalAttachments, string defaultContentTypeId, string status) { int documentCount = 0, count = 0; string fileNameKey = string.Empty; string overwriteDocumentURLs = string.Empty; foreach (string key in collectionOfAttachments.Keys) { fileNameKey = key.Split(new string[] { ConstantStrings.DOLLAR }, StringSplitOptions.RemoveEmptyEntries)[0]; var selectedItems = from li in listItemsColl.Cast <ListItem>() from files in li.Folder.Files where files.Name.ToUpperInvariant() == fileNameKey.ToUpperInvariant() select files; if (selectedItems.FirstOrDefault() != null) { overwriteDocumentURLs += allAttachmentUrl[count] + ConstantStrings.Semicolon; } else { SendDocumentToOneDrive(web, usersMySite, fileNameKey, collectionOfAttachments[key], collectionOfOriginalAttachments[key], defaultContentTypeId); documentCount++; } count++; web.Update(); clientContext.ExecuteQuery(); MailAttachmentDetails.CheckoutFailedPosition++; status = string.Concat(usersMySite, ServiceConstantStrings.OneDriveDocumentLibraryTitle, ConstantStrings.Semicolon, documentCount, ConstantStrings.Semicolon, collectionOfAttachments.Count, ConstantStrings.Semicolon, overwriteDocumentURLs); } return(status); }
/// <summary> /// Creates the type of the content. /// </summary> /// <param name="clientContext">The client context.</param> /// <param name="web">Object of site</param> /// <param name="siteColumns">The site columns.</param> /// <param name="contentTypeName">Name of Content Type</param> internal static bool CreateContentType(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, List <string> siteColumns, string contentTypeName, string contentTypegroup) { bool status = true; ContentType parentContentType = null; try { ContentTypeCollection contentTypeCollection = web.ContentTypes; clientContext.Load(contentTypeCollection); clientContext.Load(web.Fields); clientContext.ExecuteQuery(); parentContentType = (from ct in contentTypeCollection where ct.Name == ServiceConstantStrings.OneDriveParentContentType select ct).FirstOrDefault(); ContentTypeCreationInformation contentType = new ContentTypeCreationInformation(); contentType.Name = contentTypeName; contentType.Group = contentTypegroup; ///// contentType.Id = "0x010100B1ED198475FB3A4AABC59AAAD89B7EAD"; if (parentContentType != null) { contentType.ParentContentType = parentContentType; } ContentType finalObj = web.ContentTypes.Add(contentType); AddColumnsToContentType(web, siteColumns, finalObj); web.Update(); clientContext.ExecuteQuery(); } catch (Exception exception) { status = false; Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } return(status); }
/// <summary> /// Creates site column. /// </summary> /// <param name="clientContext">Client Context</param> /// <param name="web">Object of site</param> /// <param name="siteColumns">List of site columns</param> /// <returns>Success or Failure</returns> internal static bool CreateSiteColumn(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, List <string> siteColumns) { bool result = false; try { FieldCollection fieldCol = web.Fields; clientContext.Load(fieldCol); clientContext.ExecuteQuery(); List <Field> existingFields = fieldCol.ToList <Field>(); foreach (string columns in siteColumns) { Field field = (from fld in existingFields where fld.Title == columns && fld.TypeAsString == ServiceConstantStrings.OneDriveSiteColumnType select fld).FirstOrDefault(); if (null == field) { web.Fields.AddFieldAsXml(string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.OneDriveSiteColumnSchema, ServiceConstantStrings.OneDriveSiteColumn, ServiceConstantStrings.OneDriveContentTypeGroup), true, AddFieldOptions.DefaultValue); web.Update(); clientContext.ExecuteQuery(); } } result = true; } catch (Exception exception) { Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); result = false; } return(result); }
/// <summary> /// Determines whether the content type exists in the content type group under the specified client context. /// </summary> /// <param name="clientContext">Client context</param> /// <param name="web">Object of site</param> /// <param name="receivedContentType">Type of the received content</param> /// <param name="contentTypeGroup">The content type group</param> /// <param name="siteColumns">List of site columns</param> internal static bool IsContentTypePresentCheck(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, string receivedContentType, string contentTypeGroup, List <string> siteColumns) { bool status = true; try { ContentTypeCollection contentTypeCollection = web.ContentTypes; clientContext.Load(contentTypeCollection, contentTypes => contentTypes.Include(contentTypeProperties => contentTypeProperties.Group, contentTypeProperties => contentTypeProperties.Name).Where(contentTypeValues => (contentTypeValues.Group == ServiceConstantStrings.OneDriveContentTypeGroup) && (contentTypeValues.Name == ServiceConstantStrings.OneDriveContentTypeName))); clientContext.ExecuteQuery(); if (0 < contentTypeCollection.Count) { FieldCollection fields = contentTypeCollection[0].Fields; clientContext.Load(fields, field => field.Include(fieldType => fieldType.Title).Where(column => column.Title == ServiceConstantStrings.OneDriveSiteColumn)); clientContext.ExecuteQuery(); if (0 == fields.Count) { BriefcaseContentTypeHelperFunctions.AddColumnsToContentType(web, siteColumns, contentTypeCollection[0]); web.Update(); clientContext.ExecuteQuery(); } } else { status = BriefcaseContentTypeHelperFunctions.CreateContentType(clientContext, web, siteColumns, receivedContentType, contentTypeGroup); } } catch (Exception exception) { status = false; Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } return(status); }
internal static void Set(SPConfiguration config) { using (var spcontext = new SPContext(config.Url, config.Auth)) { SP.Web web = spcontext.Site.RootWeb; web.AllProperties[SPWebPropertyKey.SyncEnabled] = config.SyncEnabled; web.AllProperties[SPWebPropertyKey.FarmSyncEnabled] = config.FarmSyncEnabled; web.AllProperties[SPWebPropertyKey.SiteSettings] = new JavaScriptSerializer().Serialize(config.SiteProfileMappedFields); web.AllProperties[SPWebPropertyKey.FarmSettings] = new JavaScriptSerializer().Serialize(config.FarmProfileMappedFields); web.Update(); spcontext.ExecuteQuery(); } }
/// <summary> /// Uploads the document to OneDrive (Users MySite document library). /// </summary> /// <param name="requestObject">Request Object containing SharePoint App Token</param> /// <param name="collectionOfAttachments">Collection of documents with data for each document</param> /// <param name="collectionOfOriginalAttachments">Collection of documents with path of source document</param> /// <param name="usersMySite">User's My site URL</param> /// <param name="allAttachmentUrl">Attachment URL.</param> /// <param name="isOverwrite">Overwrite check</param> /// <returns>JSON string specifying path of OneDrive as success and false as failure</returns> internal static string UploadtoBriefcase(RequestObject requestObject, Dictionary <string, Stream> collectionOfAttachments, Dictionary <string, string> collectionOfOriginalAttachments, string usersMySite, string[] allAttachmentUrl, int isOverwrite) { string status = ConstantStrings.FALSE; try { using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(usersMySite), requestObject.RefreshToken)) { Microsoft.SharePoint.Client.Web web = clientContext.Web; string contentType = ServiceConstantStrings.OneDriveContentTypeName; // Get Content Type string contentTypegroup = ServiceConstantStrings.OneDriveContentTypeGroup; // Get Group of Content Type List <string> siteColumns = new List <string>(new string[] { ServiceConstantStrings.OneDriveSiteColumn }); bool isSiteColumnCreated = BriefcaseContentTypeHelperFunctions.CreateSiteColumn(clientContext, web, siteColumns); if (isSiteColumnCreated) { bool isContentTypeCreated = BriefcaseContentTypeHelperFunctions.IsContentTypePresentCheck(clientContext, web, contentType, contentTypegroup, siteColumns); if (isContentTypeCreated) { List list = web.Lists.GetByTitle(ServiceConstantStrings.OneDriveDocumentLibraryTitle); string briefcaseFolderQuery = string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.BriefcaseFolderQuery, ServiceConstantStrings.LegalBriefcaseFolder); ListItemCollection listItems = Lists.GetData(clientContext, ServiceConstantStrings.OneDriveDocumentLibraryTitle, briefcaseFolderQuery); BriefcaseContentTypeHelperFunctions.SetContentType(clientContext, list, usersMySite); string defaultContentTypeId = BriefcaseContentTypeHelperFunctions.SetOneDriveDefaultContentType(clientContext, list, contentType); if (ConstantStrings.FALSE != defaultContentTypeId) { web.Update(); if (0 == isOverwrite) { MailAttachmentDetails.CheckoutFailedPosition = 0; status = BriefcaseUtilityHelperFunctions.NewDocumentToOneDrive(clientContext, collectionOfAttachments, collectionOfOriginalAttachments, allAttachmentUrl, web, usersMySite, defaultContentTypeId); //// Undo check out in case of failure //// undo checkout all documents from position MailAttachmentDetails.checkOutFailedPosition BriefcaseHelperFunction.DiscardDocumentCheckout(requestObject, allAttachmentUrl); } else { MailAttachmentDetails.CheckoutFailedPosition = 0; status = BriefcaseUtilityHelperFunctions.OverWriteDocument(collectionOfAttachments, collectionOfOriginalAttachments, usersMySite, status, clientContext, web, listItems, defaultContentTypeId); string[] returnedStatus = status.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture)); if (ConstantStrings.TRUE == returnedStatus[0]) { BriefcaseHelperFunction.DiscardDocumentCheckout(requestObject, allAttachmentUrl); } status = returnedStatus[1]; } } else { MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeAssignDefaultContentType, TextConstants.ErrorMessageAssignDefaultContentType); throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function } } else { MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeCreateSiteContentType, TextConstants.ErrorMessageCreateSiteContentType); throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function } } else { MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeCreateSiteColumn, TextConstants.ErrorMessageCreateSiteColumn); throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function } } } catch (Exception exception) { Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); status += ConstantStrings.Semicolon + usersMySite; } return(status); }