在类似的问题中,使用此代码可以下载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)
我还使用以下内容类型进行了测试:
获得相同的结果.
哪种方法可以返回任何文件类型?
谢谢你的回答
通过在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

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