Пример #1
0
 public void UploadFileFromPathTest()
 {
     foreach (var path in CroatiaFileNames)
     {
         var fileNameWithExtension = Path.GetFileName(path);
         AzureFilesUtils.UploadFile("testDir", fileNameWithExtension, path);
     }
 }
Пример #2
0
        public ActionResult Save(IEnumerable <IFormFile> files, bool isInput = true)
        {
            try
            {
                // The Name of the Upload component is "files"
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

                        // Some browsers send file names with full path.
                        // We are only interested in the file name.
                        var fileName = Path.GetFileName(fileContent.FileName.Trim('"'));

                        var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, "App_Data", fileName);
                        var extension    = Path.GetExtension(physicalPath);


                        // The files are not actually saved in this demo
                        //file.SaveAs(physicalPath);

                        using (var fileStream = new FileStream(physicalPath, FileMode.Create))
                        {
                            file.CopyTo(fileStream);
                            if (isInput)
                            {
                                ControllerContext.HttpContext.Session.SetString("lastPhysicalPathInput", physicalPath);
                                //lastPhysicalPathInput = physicalPath;
                            }
                            else
                            {
                                ControllerContext.HttpContext.Session.SetString("lastPhysicalPathOutput", physicalPath);
                                //lastPhysicalPathOutput = physicalPath;
                                return(Content(""));
                            }
                        }

                        CompanyPdfMetaData cpmd            = Utils.GetCompanyPdfMetaData(physicalPath);
                        string             fileNameInAzure = $"From {cpmd.StartPeriodOfReport.Day}_{cpmd.StartPeriodOfReport.Month}_{cpmd.StartPeriodOfReport.Year} to {cpmd.EndPeriodOfReport.Day}_{cpmd.EndPeriodOfReport.Month}_{cpmd.EndPeriodOfReport.Year}{extension}";

                        var url = AzureFilesUtils.UploadFile(cpmd.CompanyName, fileNameInAzure, physicalPath);
                        HttpContext.Session.SetString("url", url);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Return an empty string to signify success
            return(Content(""));
        }
Пример #3
0
        public IActionResult Excel()
        {
            //var document = ...
            var cd = new System.Net.Mime.ContentDisposition
            {
                // for example foo.bak
                FileName = "test.pdf",

                // always prompt the user for downloading, set to true if you want
                // the browser to try to show the file inline
                Inline = false,
            };


            Response.Headers.Add("Content-Disposition", cd.ToString());

            string sWebRootFolder = HostingEnvironment.WebRootPath;

            // Decide country File type
            string lastPhysicalPathInput  = ControllerContext.HttpContext.Session.GetString("lastPhysicalPathInput");
            string lastPhysicalPathOutput = ControllerContext.HttpContext.Session.GetString("lastPhysicalPathOutput");

            string outputExcelFilePath = Utils.GetExcelOutputFilePath(sWebRootFolder, lastPhysicalPathInput, lastPhysicalPathOutput);

            CompanyPdfMetaData cpmd            = Utils.GetCompanyPdfMetaData(lastPhysicalPathInput);
            string             fileNameInAzure = $"From {cpmd.StartPeriodOfReport.Day}_{cpmd.StartPeriodOfReport.Month}_{cpmd.StartPeriodOfReport.Year} to {cpmd.EndPeriodOfReport.Day}_{cpmd.EndPeriodOfReport.Month}_{cpmd.EndPeriodOfReport.Year}.xlsm";
            string             url             =
                AzureFilesUtils.UploadFile(cpmd.CompanyName, fileNameInAzure, outputExcelFilePath);

            HttpContext.Session.SetString("excelUrl", url);
            var result = PhysicalFile(outputExcelFilePath, "application/vnd.ms-excel.sheet.macroEnabled.12");

            Response.Headers["Content-Disposition"] = new ContentDispositionHeaderValue("attachment")
            {
                FileName = Path.GetFileName(outputExcelFilePath)
            }.ToString();

            var result2 = url.ToString();//.EncodeBase64Safe();

            return(Json(result2));
        }
Пример #4
0
 public ActionResult AzureFiles_Destroy([DataSourceRequest] DataSourceRequest request,
                                        AzureCloudFileViewModel azureCloudFileViewModel)
 {
     AzureFilesUtils.DeleteFileByUri(azureCloudFileViewModel.Uri);
     return(Json(new[] { azureCloudFileViewModel }.ToDataSourceResult(request, ModelState)));
 }
Пример #5
0
        public void ListFilesTest()
        {
            var list = AzureFilesUtils.ListAllFiles();

            Assert.NotEmpty(list);
        }