public void UploadFileToSharepoint() { IFormFile file = Request.Form.Files[0]; using (var fileStream = file.OpenReadStream()) { var result = ConvertStreamToByteArray(fileStream); Stream stream = new MemoryStream(result); var token = new TokenState(); _token.TryGetValue("token", out token); SharePointFileHelper.UploadFileInSharePointSite(token.AccessToken, _configuration["SharepointSiteName"], _configuration["SharepointTenantName"] + ":", file.FileName, stream); }; }
// Invoked after success of prompt step async. private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Get the token from the previous step. Note that we could also have gotten the // token directly from the prompt itself. There is an example of this in the next method. var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse != null) { if (stepContext.Context.Activity.Text != null) { if (stepContext.Context.Activity.Text.ToLower().Trim() == "viewfile") { var fileNameList = await SharePointFileHelper.GetSharePointFile(tokenResponse, _configuration["SharePointSiteName"], _configuration["SharePointTenantName"] + ":"); if (fileNameList.Count == 0) { await stepContext.Context.SendActivityAsync(MessageFactory.Text("No files found. Please type 'uploadfile' to upload file to SharePoint site"), cancellationToken); } else { var sharePointTenantName = _configuration["SharePointTenantName"]; var sharePointSiteName = _configuration["SharePointSiteName"]; var fileUrl = ""; var actions = new List <AdaptiveAction>(); foreach (var file in fileNameList) { var extension = file.Split('.')[1]; fileUrl = $"https://teams.microsoft.com/_#/{extension}/viewer/teams/https:~2F~2F{sharePointTenantName}~2Fsites~2F{sharePointSiteName}~2FShared%20Documents~2F{file}"; actions.Add(new AdaptiveOpenUrlAction { Title = file.Split('.')[0], Url = new Uri(fileUrl), }); } await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(GetAdaptiveCardForFileViewerOption(actions)), cancellationToken); } return(await stepContext.EndDialogAsync()); } else if (stepContext.Context.Activity.Text.ToLower().Trim() == "uploadfile") { TokenState token = new TokenState { AccessToken = tokenResponse.Token }; _Token.AddOrUpdate("token", token, (key, newValue) => token); await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(GetAdaptiveCardForUploadFileOption()), cancellationToken); return(await stepContext.EndDialogAsync()); } } } await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login successful"), cancellationToken); await stepContext.Context.SendActivityAsync(MessageFactory.Text("Please type 'uploadfile' to upload file to SharePoint site or 'viewfile' to get card for file viewer"), cancellationToken); return(await stepContext.EndDialogAsync()); }