Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using System.IO;
- using System.Net.Http;
- using System.Web;
- using System.Net.Http.Headers;
- using System.Diagnostics;
- using System;
- using System.Globalization;
- using Microsoft.Extensions.FileProviders;
- using Newtonsoft.Json;
- namespace challenge.Web.Controllers.maps
- {
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class MapsController : Controller
- {
- private IHostingEnvironment _hostingEnvironment;
- public MapsController(IHostingEnvironment hostingEnvironment)
- {
- _hostingEnvironment = hostingEnvironment;
- }
- [HttpPost, DisableRequestSizeLimit]
- public ActionResult UploadFile()
- {
- try
- {
- // var obj = JsonConvert.SerializeObject(context.Request);
- var xml = Request.Form.Files["File"].ToString();
- var httpRequest = HttpContext.Request.Form;
- var postedFile = httpRequest.Files["File"];
- string outputFile = Request.Form["ProcessingMode"].ToString();
- var startDate = Request.Form["StartDate"];
- var file = httpRequest.Files[0];
- string fullPath = "";
- string folderName = "Upload";
- string antFile = @"C:\Users\Monika\Downloads\Generatorius\Generator\apache-ant-1.7.0\bin\ant.bat";
- string build = @"C:\Users\Monika\Downloads\Generatorius\Generator\build.xml";
- string rootPath = @"C:\Users\Monika\Downloads\Generatorius\Generator";
- string newPath = Path.Combine(rootPath, folderName);
- if (!Directory.Exists(newPath))
- {
- Directory.CreateDirectory(newPath);
- }
- if (file.Length > 0)
- {
- string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
- fullPath = Path.Combine(newPath, fileName);
- using (var stream = new FileStream(fullPath, FileMode.Create))
- {
- file.CopyTo(stream);
- }
- }
- string inputFile = fullPath;
- /*
- ProcessStartInfo procStartInfo5 = new ProcessStartInfo();
- procStartInfo5.FileName = "cmd.exe";
- procStartInfo5.Arguments = $"/c{antFile} -f={build} -DinputFile={inputFile} -DstartDate={startDate} -DxslFile=ProcessingDate -DoutputFile={outputFile}";
- Process.Start(procStartInfo5);
- */
- //var fs = System.IO.File.OpenRead(inputFile);
- // var result = System.Text.Encoding.UTF8.GetBytes(@"C:\work\itvs\SYSANA\DP-5\XML_generatorius\Generator\Upload\aaaa.xml");
- // return File(result, "application/xml", "aaaa.xml");
- // GetChallenges();
- // return PhysicalFile(@"C:\Users\Monika\Downloads\Generatorius\Book1.xml", "application/xml", "Book1.xml");
- //if (System.IO.File.Exists("C:\\Users\\Monika\\Downloads\\Generatorius\\Book1.xml"))
- // {// to know if the file is Exist or not
- // //Process File Here ...
- // }
- // else
- // {
- // return Json("NotFound");
- // }
- string contentType = "application/xml";
- HttpContext.Response.ContentType = contentType;
- var result = new FileContentResult(System.IO.File.ReadAllBytes("C:\\Users\\Monika\\Downloads\\Book1.xml"), contentType)
- {
- // FileDownloadName = $"{myFile.Title }" // + myFile.Extension
- FileDownloadName = "s.xml"
- };
- // System.IO.File.Delete (myFile.Path); //if you want to delete the file after download
- return result;
- }
- catch (Exception err)
- {
- Console.WriteLine(err);
- }
- return BadRequest();
- }
- //[HttpGet]
- //public IActionResult GetChallenges()
- //{
- // var physicalFilePath = "C:\\Users\\Monika\\Downloads\\Book1.xml";
- // var fileBytes = System.IO.File.ReadAllBytes(physicalFilePath);
- // return this.File(fileBytes, "text/xml", "test.xml");
- // // return PhysicalFile(@"C:\Users\Monika\Downloads\Book1.xml", "application/xml", "Book1.xml");
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement