小编Jos*_*res的帖子

如何从WebAPI ASP.NET Core返回Excel文件

在类似的问题中,使用此代码可以下载PDF:

我正在使用Controller文件夹中的本地文件(.xlsx,.pdf,.zip)进行测试.

类似的问题

[HttpGet("downloadPDF")]
public FileResult TestDownloadPCF()
{
   HttpContext.Response.ContentType = "application/pdf";
   FileContentResult result = new FileContentResult
   (System.IO.File.ReadAllBytes("Controllers/test.pdf"), "application/pdf")
    {
      FileDownloadName = "test.pdf"
    };
   return result;
}
Run Code Online (Sandbox Code Playgroud)

这很棒!

但是当另一个文件?,例如Excel文件(.xlsx)或ZIP文件(.zip)时,测试无法正常工作.

代码:

[HttpGet("downloadOtherFile")]
public FileResult TestDownloadOtherFile()
{
  HttpContext.Response.ContentType = 
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  FileContentResult result = new FileContentResult(System.IO.File.ReadAllBytes("Controllers/test.xlsx"), 
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  {
    FileDownloadName = "otherfile"
   };
  return result;
}
Run Code Online (Sandbox Code Playgroud)

结果: 在此输入图像描述

我还使用以下内容类型进行了测试:

  • "Application/vnd.ms-excel"
  • "Application/vnd.ms-excel.12"

获得相同的结果.

哪种方法可以返回任何文件类型?

谢谢你的回答

c# http asp.net-web-api asp.net-core asp.net-core-1.0

12
推荐指数
2
解决办法
1万
查看次数

Xamarin"Aapt.exe"退出,代码为-1073741819

通过在Visual Studio 2015中使用API​​ 19(4.4.2)创建Android项目,当我想启动应用程序时向我显示这些错误.

看

错误1: "aapt.exe"退出代码 - 1073741819.APP_Activity_Sync C:\ Program Files(x86)\ MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1665

错误2:文件"obj\Debug\android\bin\packaged_resources"不存在.APP_Activity_Sync C:\ Program Files(x86)\ MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1691

我将所有文件都下载了API19和SDK Manager.

SDK详细信息API19

SDK详细信息API19

有人想要类似的事情发生,这个问题的解决方案是什么?

c# android xamarin.android visual-studio-2015

10
推荐指数
2
解决办法
5065
查看次数