public override Task <FolderFilesReply> FolderFiles(FolderFilesRequest request, ServerCallContext context) { var result = new FolderFilesReply(); // Get the file details list in folder List <Interfaces.SharePointFileManager.FileDetailsList> fileDetailsList = null; SharePointFileManager _sharePointFileManager = new SharePointFileManager(_configuration); try { fileDetailsList = _sharePointFileManager.GetFileDetailsListInFolder(GetDocumentTemplateUrlPart(request.EntityName), request.FolderName, request.DocumentType).GetAwaiter().GetResult(); if (fileDetailsList != null) { // gRPC ensures that the collection has space to accept new data; no need to call a constructor foreach (var item in fileDetailsList) { // Sharepoint API responds with dates in UTC format var utcFormat = DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal; DateTime parsedCreateDate, parsedLastModified; DateTime.TryParse(item.TimeCreated, CultureInfo.InvariantCulture, utcFormat, out parsedCreateDate); DateTime.TryParse(item.TimeLastModified, CultureInfo.InvariantCulture, utcFormat, out parsedLastModified); FileSystemItem newItem = new FileSystemItem() { DocumentType = item.DocumentType, Name = item.Name, ServerRelativeUrl = item.ServerRelativeUrl, Size = int.Parse(item.Length), TimeCreated = parsedCreateDate != null?Timestamp.FromDateTime(parsedCreateDate) : null, TimeLastModified = parsedLastModified != null?Timestamp.FromDateTime(parsedLastModified) : null, }; result.Files.Add(newItem); } result.ResultStatus = ResultStatus.Success; } } catch (SharePointRestException spre) { Log.Error(spre, "Error getting SharePoint File List"); result.ResultStatus = ResultStatus.Fail; result.ErrorDetail = "Error getting SharePoint File List"; } return(Task.FromResult(result)); }
public override Task <FolderFilesReply> FolderFiles(FolderFilesRequest request, ServerCallContext context) { var result = new FolderFilesReply(); // Get the file details list in folder List <Interfaces.SharePointFileManager.FileDetailsList> fileDetailsList = null; SharePointFileManager _sharePointFileManager = new SharePointFileManager(_configuration); try { fileDetailsList = _sharePointFileManager.GetFileDetailsListInFolder(GetDocumentTemplateUrlPart(request.EntityName), request.FolderName, request.DocumentType).GetAwaiter().GetResult(); if (fileDetailsList != null) { // gRPC ensures that the collection has space to accept new data; no need to call a constructor foreach (var item in fileDetailsList) { FileSystemItem newItem = new FileSystemItem() { DocumentType = item.DocumentType, Name = item.Name, ServerRelativeUrl = item.ServerRelativeUrl, Size = int.Parse(item.Length) }; result.Files.Add(newItem); } result.ResultStatus = ResultStatus.Success; } } catch (SharePointRestException spre) { _logger.LogError(spre, "Error getting SharePoint File List"); result.ResultStatus = ResultStatus.Fail; result.ErrorDetail = "Error getting SharePoint File List"; } return(Task.FromResult(result)); }