Example #1
0
        public async Task ApproveFileAsync(IConfiguration configuration)
        {
            string readFileFromTemp = System.IO.File.ReadAllText(@"Temp/TempFile.txt");

            if (System.IO.File.Exists(readFileFromTemp))
            {
                SharePointRepository repository = new SharePointRepository(configuration);
                await repository.UploadFileToSPAsync(readFileFromTemp, false);
            }
        }
        public async Task <IActionResult> Upload(FileUploadViewModel fileUpload)
        {
            if (ModelState.IsValid)
            {
                string uploadsfolder  = Path.Combine(this.hostingEnvironment.WebRootPath, "Files");
                string uniqueFileName = Guid.NewGuid().ToString() + "_" + fileUpload.File.FileName;
                string fileLocation   = @"wwwroot/Files/" + uniqueFileName;
                if (fileUpload.File != null)
                {
                    // Write it to server.
                    using (FileStream fs = System.IO.File.Create(fileLocation))
                    {
                        await fileUpload.File.CopyToAsync(fs);
                    }

                    SharePointRepository repository = new SharePointRepository(configuration);

                    if (await repository.UploadFileToSPAsync(fileLocation, true))
                    {
                        var tempFilePath = @"Temp/TempFile.txt";
                        System.IO.File.WriteAllText(tempFilePath, fileLocation);

                        //send the card to channel based on team member role
                        ChannelHandler channelHandler = new ChannelHandler();
                        await channelHandler.SendConversation(configuration);

                        return(View("Create"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Failed to upload your file. Please try again later.");
                    }
                }
            }

            return(View(fileUpload));
        }