public GenericResponseVM UploadDocument(string folderName, IFormFile uploadedFile, string fileName, Dictionary <string, string> mailProperties, string clientUrl, string folder, string documentLibraryName, MatterExtraProperties documentExtraProperites) { return(spList.UploadDocument(folderName, uploadedFile, fileName, mailProperties, clientUrl, folder, documentLibraryName, documentExtraProperites)); }
public void SetUploadItemProperties(ClientContext clientContext, string documentLibraryName, string fileName, string folderPath, Dictionary <string, string> mailProperties, MatterExtraProperties documentExtraProperties) { spList.SetUploadItemProperties(clientContext, documentLibraryName, fileName, folderPath, mailProperties, documentExtraProperties); }
/// <summary> /// Assigns field values for specified content types to the specified matter (document library). /// </summary> /// <param name="clientContext">SP client context</param> /// <param name="contentTypeCollection">Collection of content types</param> /// <param name="matterList">List containing matters</param> /// <param name="matterMetadata">Object containing metadata for Matter</param> private void SetFieldValues(ClientContext clientContext, IList <ContentType> contentTypeCollection, List matterList, MatterMetadata matterMetadata) { try { FieldCollection fields = GetContentType(clientContext, contentTypeCollection, matterList); if (null != fields) { matterMetadata = GetWSSId(clientContext, matterMetadata, fields); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).DefaultValue = matterMetadata.Client.Id; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).SetShowInDisplayForm(true); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).ReadOnlyField = true; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).Update(); if (configuration.GetSection("General")["IsBackwardCompatible"].ToString().ToLower() == "false") { fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).SetShowInDisplayForm(true); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).DefaultValue = matterMetadata.Client.Name; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).ReadOnlyField = true; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).Update(); } fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).DefaultValue = matterMetadata.Matter.Id; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).SetShowInDisplayForm(true); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).ReadOnlyField = true; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).Update(); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).DefaultValue = matterMetadata.Matter.Name; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).ReadOnlyField = true; fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).SetShowInDisplayForm(true); fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).Update(); int levels = taxonomySettings.Levels; //For the number of levels that are configured, get the configured column name and //update the wssid, termname and id for the managed field for (int i = 1; i <= levels; i++) { string columnName = configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName" + i]; fields.GetByInternalNameOrTitle(columnName).SetShowInDisplayForm(true); ManagedColumn managedColumn = matterMetadata.ManagedColumnTerms[columnName]; fields.GetByInternalNameOrTitle(columnName).DefaultValue = string.Format(CultureInfo.InvariantCulture, ServiceConstants.MetadataDefaultValue, managedColumn.WssId, managedColumn.TermName, managedColumn.Id); fields.GetByInternalNameOrTitle(columnName).Update(); } //To set the values of new content type site columns and update it in sharepoint . //Update the values of site columns of Additional content type at Matter level MatterExtraProperties matterExtraProperties = matterMetadata.MatterExtraProperties;; foreach (var extraField in matterExtraProperties.Fields) { if (extraField.Type == "Text") { fields.GetByInternalNameOrTitle(extraField.FieldName).DefaultValue = extraField.FieldValue; fields.GetByInternalNameOrTitle(extraField.FieldName).SetShowInDisplayForm(true); fields.GetByInternalNameOrTitle(extraField.FieldName).Update(); } else { fields.GetByInternalNameOrTitle(extraField.FieldName).DefaultValue = extraField.FieldValue; fields.GetByInternalNameOrTitle(extraField.FieldName).Update(); } } } } catch (Exception exception) { customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } }
public IActionResult UploadFiles() { try { IFormFileCollection fileCollection = Request.Form.Files; Regex regEx = new Regex("[*?|\\\t/:\"\"'<>#{}%~&]"); string clientUrl = Request.Form["clientUrl"]; string folderUrl = Request.Form["folderUrl"]; string folderName = folderUrl.Substring(folderUrl.LastIndexOf(ServiceConstants.FORWARD_SLASH, StringComparison.OrdinalIgnoreCase) + 1); string documentLibraryName = Request.Form["documentLibraryName"]; MatterExtraProperties documentExtraProperites = null; if (!string.IsNullOrWhiteSpace(Request.Form["DocumentExtraProperties"])) { documentExtraProperites = JsonConvert.DeserializeObject <MatterExtraProperties>(Request.Form["DocumentExtraProperties"].ToString()); } bool isDeployedOnAzure = Convert.ToBoolean(generalSettings.IsTenantDeployment, CultureInfo.InvariantCulture); string originalName = string.Empty; bool allowContentCheck = Convert.ToBoolean(Request.Form["AllowContentCheck"], CultureInfo.InvariantCulture); Int16 isOverwrite = 3; //Input validation #region Error Checking GenericResponseVM genericResponse = null; IList <object> listResponse = new List <object>(); bool continueUpload = true; if (isDeployedOnAzure == false && string.IsNullOrWhiteSpace(clientUrl) && string.IsNullOrWhiteSpace(folderUrl)) { genericResponse = new GenericResponseVM() { Value = errorSettings.MessageNoInputs, Code = HttpStatusCode.BadRequest.ToString(), IsError = true }; return(matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK)); } #endregion //Get all the files which are uploaded by the user for (int fileCounter = 0; fileCounter < fileCollection.Count; fileCounter++) { IFormFile uploadedFile = fileCollection[fileCounter]; if (!Int16.TryParse(Request.Form["Overwrite" + fileCounter], out isOverwrite)) { isOverwrite = 3; } continueUpload = true; ContentDispositionHeaderValue fileMetadata = ContentDispositionHeaderValue.Parse(uploadedFile.ContentDisposition); string fileName = originalName = fileMetadata.FileName.Trim('"'); fileName = System.IO.Path.GetFileName(fileName); ContentCheckDetails contentCheckDetails = new ContentCheckDetails(fileName, uploadedFile.Length); string fileExtension = System.IO.Path.GetExtension(fileName).Trim(); if (-1 < fileName.IndexOf('\\')) { fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1); } else if (-1 < fileName.IndexOf('/')) { fileName = fileName.Substring(fileName.LastIndexOf('/') + 1); } if (null != uploadedFile.OpenReadStream() && 0 == uploadedFile.OpenReadStream().Length) { listResponse.Add(new GenericResponseVM() { Code = fileName, Value = errorSettings.ErrorEmptyFile, IsError = true }); } else if (regEx.IsMatch(fileName)) { listResponse.Add(new GenericResponseVM() { Code = fileName, Value = errorSettings.ErrorInvalidCharacter, IsError = true }); } else { string folder = folderUrl.Substring(folderUrl.LastIndexOf(ServiceConstants.FORWARD_SLASH, StringComparison.OrdinalIgnoreCase) + 1); //If User presses "Perform content check" option in overwrite Popup if (2 == isOverwrite) { genericResponse = documentProvision.PerformContentCheck(clientUrl, folderUrl, uploadedFile, fileName); } //If user presses "Cancel upload" option in overwrite popup or file is being uploaded for the first time else if (3 == isOverwrite) { genericResponse = documentProvision.CheckDuplicateDocument(clientUrl, folderUrl, documentLibraryName, fileName, contentCheckDetails, allowContentCheck); } //If User presses "Append date to file name and save" option in overwrite Popup else if (1 == isOverwrite) { string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(fileName); string timeStampSuffix = DateTime.Now.ToString(documentSettings.TimeStampFormat, CultureInfo.InvariantCulture).Replace(":", "_"); fileName = fileNameWithoutExt + "_" + timeStampSuffix + fileExtension; } if (genericResponse == null) { genericResponse = documentProvision.UploadFiles(uploadedFile, fileExtension, originalName, folderUrl, fileName, clientUrl, folder, documentLibraryName, documentExtraProperites); } if (genericResponse == null) { string documentIconUrl = string.Empty; fileExtension = fileExtension.Replace(".", ""); if (fileExtension.ToLower() != "pdf") { documentIconUrl = $"{generalSettings.SiteURL}/_layouts/15/images/ic{fileExtension}.gif"; } else { documentIconUrl = $"{generalSettings.SiteURL}/_layouts/15/images/ic{fileExtension}.png"; } //Create a json object with file upload success var successFile = new { IsError = false, Code = HttpStatusCode.OK.ToString(), Value = UploadEnums.UploadSuccess.ToString(), FileName = fileName, DropFolder = folderName, DocumentIconUrl = documentIconUrl }; listResponse.Add(successFile); } else { //Create a json object with file upload failure var errorFile = new { IsError = true, Code = genericResponse.Code.ToString(), Value = genericResponse.Value.ToString(), FileName = fileName, DropFolder = folderName }; listResponse.Add(errorFile); } } } //Return the response with proper http status code and proper response object return(matterCenterServiceFunctions.ServiceResponse(listResponse, (int)HttpStatusCode.OK)); } catch (Exception ex) { customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } }
public GenericResponseVM UploadFiles(IFormFile uploadedFile, string fileExtension, string originalName, string folderName, string fileName, string clientUrl, string folder, string documentLibraryName, MatterExtraProperties documentExtraProperites) { GenericResponseVM genericResponse = null; try { Dictionary <string, string> mailProperties = ContinueUpload(uploadedFile, fileExtension); //setting original name property for attachment if (string.IsNullOrWhiteSpace(mailProperties[ServiceConstants.MailOriginalName])) { mailProperties[ServiceConstants.MAIL_ORIGINAL_NAME] = originalName; } genericResponse = docRepository.UploadDocument(folderName, uploadedFile, fileName, mailProperties, clientUrl, folder, documentLibraryName, documentExtraProperites); } catch (Exception ex) { genericResponse = new GenericResponseVM() { Code = UploadEnums.UploadFailure.ToString(), Value = folderName, IsError = true }; } return(genericResponse); }