首页 > 解决方案 > 在 asp.net core 中使用 WordprocessingDocument 返回 500 错误

问题描述

您好,我使用 WordprocessingDocument 读取 word 文件的文本,但在发送文件 WordprocessingDocument 后,我​​的控制器返回 500 错误:

 public async Task<IActionResult> UploadFile([FromForm] IFormFile file)
        {

            string path = Path.Combine(_env.ContentRootPath, "wwwroot", "uploadFiles");
            using (var fs = new FileStream(Path.Combine(path, file.FileName), FileMode.Create))
            {

                 file.CopyTo(fs);

                var stream = new FileStream(Path.Combine(path, file.FileName), FileMode.Open);
                using (WordprocessingDocument doc = WordprocessingDocument.Create(stream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
                {
                    MainDocumentPart mainPart = doc.MainDocumentPart;

                    Body body = mainPart.Document.Body;
                    return new JsonResult(body);
                }
            }


        }

在 word proccer 使用代码正常工作之后 wordproccer 代码继续没有错误但得到 500 错误响应

在此处输入图像描述

标签: asp.netasp.net-core

解决方案


推荐阅读