Repository navigation
Expand file tree
/
Copy pathHomeController.cs
More file actions
42 lines (36 loc) · 1.65 KB
/
Copy pathHomeController.cs
File metadata and controls
42 lines (36 loc) · 1.65 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
using DevExpress.AspNetCore.Spreadsheet;
using FileManagerOpenDocuments.Models;
using Microsoft.AspNetCore.Mvc;
namespace FileManagerOpenDocuments.Controllers {
public class HomeController : Controller {
private readonly string rootPath;
public HomeController(IWebHostEnvironment hostingEnvironment) {
rootPath = Path.Combine(hostingEnvironment.WebRootPath, "SampleDocs");
}
[HttpPost]
public IActionResult OpenDocInSpreadsheet(string filePath) {
if (string.IsNullOrWhiteSpace(filePath)) {
return BadRequest("A document path is required.");
}
string path = Path.GetFullPath(Path.Combine(rootPath, filePath));
string relativePath = Path.GetRelativePath(rootPath, path);
if (Path.IsPathRooted(relativePath) || relativePath == ".." ||
relativePath.StartsWith($"..{Path.DirectorySeparatorChar}") ||
!string.Equals(Path.GetExtension(path), ".xlsx", StringComparison.OrdinalIgnoreCase)) {
return BadRequest("Select an XLSX document in SampleDocs.");
}
if (!System.IO.File.Exists(path)) {
return NotFound("The document was not found.");
}
return PartialView("SpreadsheetPartial", new DocumentModel {
DocumentID = relativePath,
FileBytes = System.IO.File.ReadAllBytes(path)
});
}
[HttpPost]
[HttpGet]
public IActionResult DxDocRequest() {
return SpreadsheetRequestProcessor.GetResponse(HttpContext);
}
}
}