Beispiel #1
0
        public IActionResult UploadTemplate()
        {
            Stream uploadFileStream = null;
            string templateName;

            if (this.HttpContext.Request.HasFormContentType)
            {
                uploadFileStream = this.HttpContext.Request.Form.Files[0].OpenReadStream();
                templateName     = this.HttpContext.Request.Form.Files[0].FileName;
            }
            else
            {
                if (this.HttpContext.Request.QueryString.HasValue)
                {
                    templateName = HttpContext.Request.QueryString.Value;
                }
                else
                {
                    var guid = Guid.NewGuid().ToString("N");
                    templateName = string.Format("template_{0}.docx", guid);
                }

                uploadFileStream = this.HttpContext.Request.Body;
            }

            string xml       = null;
            var    docHelper = new DocumentHelper(templateName);

            using (var fileStream = System.IO.File.Create(Path.Combine(_pathTemplates, templateName)))
            {
                uploadFileStream.CopyTo(fileStream);
                xml = DocumentProcessor.GetDocumentXml(fileStream, docHelper.DocumentPath);
            }

            if (string.IsNullOrWhiteSpace(xml))
            {
                return(new JsonResult("Incorrect File Format"));
            }

            var list = DocumentProcessor.GetListOfFields(xml);
            var ur   = new TemplateInfo {
                Fields = list.ToDictionary(x => x), TemplateName = templateName
            };

            return(new JsonResult(ur));
        }
Beispiel #2
0
        public IActionResult GetTemplateInfo(string filename)
        {
            string xml       = null;
            var    docHelper = new DocumentHelper(filename);

            xml = DocumentProcessor.GetDocumentXml(Path.Combine(_pathTemplates, filename), docHelper.DocumentPath);

            if (string.IsNullOrWhiteSpace(xml))
            {
                return(new JsonResult("Incorrect File Format"));
            }

            var list = DocumentProcessor.GetListOfFields(xml);
            var ur   = new TemplateInfo {
                Fields = list.ToDictionary(x => x), TemplateName = filename
            };

            return(new JsonResult(ur));
        }