Пример #1
0
        public ActionResult UploadFile(FileModel file)
        {
            var list = _filesService.ReadFileToObj(file.Bytes, new OrderXmlFileFormatter());
            _orderService.SaveOrders(list);

            return RedirectToAction("Index");
        }
Пример #2
0
        private FileModel CreateFileModel(HttpPostedFileBase fileBase)
        {
            var file = new FileModel
            {
                Name = fileBase.FileName,
                Extension = fileBase.FileName.Substring(fileBase.FileName.LastIndexOf('.') + 1),
                Size = fileBase.ContentLength
            };

            using (var stream = fileBase.InputStream)
            {
                var memoryStream = stream as MemoryStream;
                if (memoryStream == null)
                {
                    memoryStream = new MemoryStream();
                    stream.CopyTo(memoryStream);
                }
                file.Bytes = memoryStream.GetBuffer();
            }

            return file;
        }