asp.net - 在 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 错误响应
解决方案
推荐阅读
- vba - 根据用户表单选择更新电子表格上的多行
- node.js - 如何在 node graphicsmagick 中使用自定义命令?
- python - 读取文本文件并提取制表符和空格划分的部分
- ruby - 如何在新的 GitHub 存储库中自动创建问题?
- docker - 如何在适用于 Linux 的 Windows 子系统上的 docker 中使用 -v 卷参数
- node.js - 在每次源文件更改时自动运行 Mocha 测试
- r - 反向摘要以扩展数据框中的逗号分隔字符串
- python - 带有 CleverHans 的随机森林黑盒
- python - 为什么 Python Pandas loc 不返回单个项目?
- c# - DbContext 不包含配置的定义 - EF Core