forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerBaseExtensions.cs
More file actions
30 lines (26 loc) · 993 Bytes
/
ControllerBaseExtensions.cs
File metadata and controls
30 lines (26 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Microsoft.AspNetCore.Mvc;
using SSCMS.Utils;
namespace SSCMS.Extensions
{
public static class ControllerBaseExtensions
{
public static FileContentResult Download(this ControllerBase controller, string filePath, string fileName)
{
//return controller.File(filePath, "application/force-download", fileName);
var fileBytes = System.IO.File.ReadAllBytes(filePath);
return controller.File(fileBytes, "application/force-download", fileName);
}
public static FileContentResult Download(this ControllerBase controller, string filePath)
{
var fileName = PathUtils.GetFileName(filePath);
return Download(controller, filePath, fileName);
}
public static BadRequestObjectResult Error(this ControllerBase controller, string message)
{
return controller.BadRequest(new
{
Message = message
});
}
}
}