44 |
45 | An error has occurred. This application may no longer respond until reloaded.
46 |
47 |
48 | An unhandled exception has occurred. See browser dev tools for details.
49 |
50 | Reload
51 | 🗙
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/server/Components/Routes.razor:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/server/Components/_Imports.razor:
--------------------------------------------------------------------------------
1 | @using System.Net.Http
2 | @using Microsoft.AspNetCore.Authorization
3 | @using Microsoft.AspNetCore.Components.Authorization
4 | @using Microsoft.AspNetCore.Components.Forms
5 | @using Microsoft.AspNetCore.Components.Routing
6 | @using Microsoft.AspNetCore.Components.Web
7 | @using Microsoft.JSInterop
8 | @using DocumentExplorer
9 | @using DocumentExplorer.Models
10 | @using DocumentExplorer.Shared
11 | @using Newtonsoft.Json
12 | @using Newtonsoft.Json.Linq
13 | @using Syncfusion.Blazor
14 | @using Syncfusion.Blazor.Navigations
15 | @using Microsoft.AspNetCore.WebUtilities
16 | @using System.Text
17 | @using IO = System.IO
18 | @inject IJSRuntime JSRuntime
19 | @inject HttpClient Http
20 | @inject NavigationManager NavigationManager;
21 |
--------------------------------------------------------------------------------
/server/Controllers/DocumentEditorController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Drawing;
4 | using System.Collections.Generic;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Mvc;
7 | //File Manager's base functions are available in the below namespace
8 | using DocumentExplorer.Models.FileManager;
9 | using Syncfusion.Blazor.DocumentEditor;
10 | using DocIO = Syncfusion.DocIO.DLS;
11 | using Syncfusion.DocIORenderer;
12 | using Syncfusion.Pdf;
13 | using Syncfusion.Blazor.SfPdfViewer;
14 | using DocumentExplorer.Models;
15 | using SkiaSharp;
16 | using System.Text.Json;
17 |
18 | namespace DocumentExplorer.Controllers
19 | {
20 | [Route("api/[controller]")]
21 | [ApiController]
22 | public class DocumentEditorController : ControllerBase
23 | {
24 | private string basePath;
25 | private string baseLocation;
26 | IWebHostEnvironment _hostingEnvironment;
27 | public DocumentEditorController(IWebHostEnvironment hostingEnvironment)
28 | {
29 | _hostingEnvironment = hostingEnvironment;
30 | this.basePath = _hostingEnvironment.ContentRootPath;
31 | this.baseLocation = this.basePath + "\\wwwroot\\";
32 | }
33 |
34 | [Route("Import")]
35 | public string Import([FromBody] FileManagerDirectoryContent args)
36 | {
37 | string fileLocation = this.baseLocation + args.Path.Replace("/", "\\");
38 | using (FileStream fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read))
39 | {
40 | WordDocument document = WordDocument.Load(fs, GetImportFormatType(Path.GetExtension(fileLocation).ToLower()));
41 | string json = JsonSerializer.Serialize(document);
42 | document.Dispose();
43 | return json;
44 | }
45 | }
46 | private List ConvertToImages(FileStream fs, List returnStrings, Syncfusion.DocIO.FormatType type)
47 | {
48 | //DocIO.WordDocument wd = new DocIO.WordDocument(fs, type);
49 | ////Instantiation of DocIORenderer for Word to PDF conversion
50 | //DocIORenderer render = new DocIORenderer();
51 | ////Converts Word document into PDF document
52 | //PdfDocument pdfDocument = render.ConvertToPDF(wd);
53 | ////Releases all resources used by the Word document and DocIO Renderer objects
54 | //render.Dispose();
55 | //wd.Dispose();
56 | ////Saves the PDF file
57 | //MemoryStream outputStream = new MemoryStream();
58 | //pdfDocument.Save(outputStream);
59 | //outputStream.Position = 0;
60 | ////Closes the instance of PDF document object
61 | //pdfDocument.Close();
62 |
63 | //SfPdfViewer2 pdfExportImage = new SfPdfViewer2();
64 | ////Loads the PDF document
65 | //pdfExportImage.LoadAsync(outputStream);
66 |
67 | ////Exports the PDF document pages into images
68 | //SKBitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, pdfExportImage.PageCount - 1);
69 | //Bitmap[] bitmapImages = new Bitmap[bitmapimage.Length];
70 |
71 | //for (int i = 0; i < bitmapimage.Length; i++)
72 | //{
73 | // using (SKImage skImage = SKImage.FromBitmap(bitmapimage[i]))
74 | // using (SKData skData = skImage.Encode(SKEncodedImageFormat.Png, 100))
75 | // using (System.IO.MemoryStream stream = new System.IO.MemoryStream(skData.ToArray()))
76 | // {
77 | // bitmapImages[i] = new Bitmap(stream);
78 | // }
79 | //}
80 |
81 | //foreach (Bitmap bitmap in bitmapImages)
82 | //{
83 | // using (MemoryStream ms = new MemoryStream())
84 | // {
85 | // bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
86 | // returnStrings.Add("data:image/png;base64," + Convert.ToBase64String(ms.ToArray()));
87 | // }
88 | //}
89 | return returnStrings;
90 | }
91 | [Route("OpenFromZip")]
92 | public string[] OpenFromZip([FromBody] FileManagerDirectoryContent args)
93 | {
94 | List returnArray = new List();
95 | using (FileStream fs = new FileStream(args.Path, FileMode.Open, FileAccess.Read))
96 | {
97 | WordDocument document = WordDocument.Load(fs, GetImportFormatType(Path.GetExtension(args.Path).ToLower()));
98 | string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
99 | document.Dispose();
100 | returnArray.Add(json);
101 | return ConvertToImages(fs, returnArray, GetDocIOFormatType(Path.GetExtension(args.Path).ToLower())).ToArray();
102 | }
103 |
104 | }
105 |
106 | private ImportFormatType GetImportFormatType(string format)
107 | {
108 | if (string.IsNullOrEmpty(format))
109 | throw new NotSupportedException("DocumentEditor does not support this file format.");
110 | switch (format.ToLower())
111 | {
112 | case Constants.Dotx:
113 | case Constants.Docx:
114 | case Constants.Docm:
115 | case Constants.Dotm:
116 | return ImportFormatType.Docx;
117 | case Constants.Dot:
118 | case Constants.Doc:
119 | return ImportFormatType.Doc;
120 | case Constants.Rtf:
121 | return ImportFormatType.Rtf;
122 | case Constants.Txt:
123 | return ImportFormatType.Txt;
124 | case Constants.Xml:
125 | return ImportFormatType.WordML;
126 | case Constants.Html:
127 | return ImportFormatType.Html;
128 | default:
129 | throw new NotSupportedException("DocumentEditor does not support this file format.");
130 | }
131 | }
132 |
133 | private Syncfusion.DocIO.FormatType GetDocIOFormatType(string format)
134 | {
135 | if (string.IsNullOrEmpty(format))
136 | throw new NotSupportedException("DocumentEditor does not support this file format.");
137 | switch (format.ToLower())
138 | {
139 | case Constants.Dotx:
140 | case Constants.Docx:
141 | case Constants.Docm:
142 | case Constants.Dotm:
143 | return Syncfusion.DocIO.FormatType.Docx;
144 | case Constants.Dot:
145 | case Constants.Doc:
146 | return Syncfusion.DocIO.FormatType.Doc;
147 | case Constants.Rtf:
148 | return Syncfusion.DocIO.FormatType.Rtf;
149 | case Constants.Txt:
150 | return Syncfusion.DocIO.FormatType.Txt;
151 | case Constants.Xml:
152 | return Syncfusion.DocIO.FormatType.WordML;
153 | case Constants.Html:
154 | return Syncfusion.DocIO.FormatType.Html;
155 | default:
156 | throw new NotSupportedException("DocumentEditor does not support this file format.");
157 | }
158 | }
159 | }
160 | }
--------------------------------------------------------------------------------
/server/Controllers/FileManagerController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using System;
3 | using System.Collections.Generic;
4 | using Microsoft.AspNetCore.Hosting;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Http.Features;
7 | //File Manager's base functions are available in the below namespace
8 | using DocumentExplorer.Models.FileManager;
9 | //File Manager's operations are available in the below namespace
10 | using DocumentExplorer.Data;
11 | using Newtonsoft.Json;
12 | using System.Linq;
13 | using System.IO;
14 | using Newtonsoft.Json.Serialization;
15 | using Microsoft.AspNetCore.Cors;
16 |
17 | namespace DocumentExplorer.Controllers
18 | {
19 | [Route("api/[controller]")]
20 | [EnableCors("AllowAllOrigins")]
21 | public class FileManagerController : ControllerBase
22 | {
23 | private PhysicalFileProvider operation;
24 | private string basePath;
25 | string root = "wwwroot\\Files";
26 | string rootPath;
27 | string virtualConnection;
28 | public FileManagerController(IWebHostEnvironment hostingEnvironment)
29 | {
30 | this.basePath = hostingEnvironment.ContentRootPath;
31 | this.operation = new PhysicalFileProvider();
32 | if (basePath.EndsWith("\\"))
33 | this.rootPath = this.basePath + this.root;
34 | else
35 | this.rootPath = this.basePath + "\\" + this.root;
36 | this.operation.RootFolder(rootPath);
37 | }
38 | // Processing the File Manager operations
39 | [Route("FileOperations")]
40 | public object FileOperations([FromBody] FileManagerCustomContent args)
41 | {
42 |
43 | args.RootType = HttpContext.Request.Headers["RootType"];
44 | string connectionId = HttpContext.Session.GetString("ConnectionId");
45 | if (args.Path == "/Files/")
46 | {
47 | args.Path = "/";
48 | }
49 | if (string.IsNullOrEmpty(connectionId))
50 | {
51 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
52 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
53 | }
54 |
55 | if (basePath.EndsWith("\\"))
56 | {
57 | virtualConnection = this.basePath + "wwwroot\\VirtualConnections";
58 | }
59 | else
60 | {
61 | virtualConnection = this.basePath + "\\wwwroot\\VirtualConnections";
62 | }
63 | DateTime currentTime = DateTime.Now;
64 | DateTime deletionThreshold = currentTime.AddHours(-24);
65 | DirectoryInfo virtualDirectoryInfo = new DirectoryInfo(virtualConnection);
66 |
67 | if (Directory.Exists(virtualConnection) && virtualDirectoryInfo.LastWriteTime <= deletionThreshold)
68 | {
69 | Directory.Delete(virtualConnection, true);
70 | }
71 | if (!Directory.Exists(virtualConnection))
72 | {
73 | //Create virtual root directory
74 | Directory.CreateDirectory(virtualConnection);
75 | }
76 | string userID = virtualConnection + "\\" + connectionId + "\\Files";
77 | string virtualUser = virtualConnection + "\\" + connectionId + "\\User";
78 | string virtualTrash = virtualConnection + "\\" + connectionId + "\\Trash";
79 | if (!Directory.Exists(userID))
80 | {
81 | Directory.CreateDirectory(userID);
82 | Directory.CreateDirectory(virtualUser);
83 | Directory.CreateDirectory(virtualTrash);
84 | CopyFolder(rootPath, userID);
85 | CopyFolder(this.basePath + "\\wwwroot\\User", virtualUser);
86 | CopyFolder(this.basePath + "\\wwwroot\\Trash", virtualTrash);
87 | }
88 |
89 | //Set user directory as root
90 | this.operation.RootFolder(userID);
91 |
92 | if (args.Action == "delete" || args.Action == "rename")
93 | {
94 | if ((args.TargetPath == null) && (args.Path == ""))
95 | {
96 | FileManagerResponse response = new FileManagerResponse();
97 | response.Error = new ErrorDetails { Code = "401", Message = "Restricted to modify the root folder." };
98 | return this.operation.ToCamelCase(response);
99 | }
100 | }
101 |
102 | switch (args.Action)
103 | {
104 | // Add your custom action here
105 | case "read":
106 | if ((args.RootType != null) && ((args.RootType == "Recent")))
107 | {
108 | FileManagerResponse result1 = this.operation.Search(args.Path, "*", args.ShowHiddenItems, false);
109 | return FilterRecentFiles(result1);
110 | }
111 | else
112 | {
113 | return this.operation.ToCamelCase(this.operation.GetFiles(args.Path, args.ShowHiddenItems));
114 | }
115 | case "delete":
116 |
117 | #if Publish
118 | FileManagerResponse deleteResponse = new FileManagerResponse();
119 | deleteResponse.Error = new ErrorDetails() { Code = "401", Message = "Restricted to perform this action" };
120 | return this.operation.ToCamelCase(deleteResponse);
121 | #else
122 | FileManagerDirectoryContent[] items1 = args.Data;
123 | string[] names1 = args.Names;
124 | return this.operation.ToCamelCase(MoveToTrash(args.Data, connectionId, virtualConnection, virtualUser));
125 | #endif
126 | case "copy":
127 | case "move":
128 | FileManagerResponse response = new FileManagerResponse();
129 | response.Error = new ErrorDetails() { Code = "401", Message = "Restricted to perform this action" };
130 | return this.operation.ToCamelCase(response);
131 | case "details":
132 | if ((args.RootType != null) && ((args.RootType == "Recent")))
133 | {
134 | FileManagerDirectoryContent[] items = args.Data;
135 | string[] names = args.Names;
136 | for (var i = 0; i < items.Length; i++)
137 | {
138 | names[i] = ((items[i].FilterPath + items[i].Name).Substring(1));
139 | }
140 | return this.operation.ToCamelCase(this.operation.Details("/", names, args.Data));
141 | }
142 | else
143 | {
144 | return this.operation.ToCamelCase(this.operation.Details(args.Path, args.Names, args.Data));
145 | }
146 | case "create":
147 | // Path - Current path where the folder is to be created; Name - Name of the new folder
148 | return this.operation.ToCamelCase(this.operation.Create(args.Path, args.Name));
149 | case "search":
150 | // Path - Current path where the search is performed; SearchString - String typed in the searchbox; CaseSensitive - Boolean value which specifies whether the search must be casesensitive
151 | if ((args.RootType != null) && ((args.RootType == "Recent")))
152 | {
153 | FileManagerResponse result1 = this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive);
154 | return FilterRecentFiles(result1);
155 | }
156 | else
157 | {
158 | return this.operation.ToCamelCase(this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive));
159 | }
160 | case "rename":
161 | // Path - Current path of the renamed file; Name - Old file name; NewName - New file name
162 | if ((args.RootType != null) && (args.RootType == "Recent"))
163 | {
164 | var items = args.Data;
165 | var name = ((items[0].FilterPath + items[0].Name).Substring(1));
166 | var newName = ((items[0].FilterPath + args.NewName).Substring(1));
167 | return this.operation.ToCamelCase(this.operation.Rename("/", name, newName));
168 | }
169 | else
170 | {
171 | return this.operation.ToCamelCase(this.operation.Rename(args.Path, args.Name, args.NewName));
172 | }
173 | }
174 | return null;
175 | }
176 | public FileManagerResponse FilterRecentFiles(FileManagerResponse result)
177 | {
178 | IEnumerable allFiles = (result.Files);
179 | allFiles = allFiles?.Where(item => item.DateModified.AddDays(5).CompareTo(DateTime.Now) != -1 && item.IsFile == true);
180 | result.Files = allFiles;
181 | return result;
182 | }
183 | public FileManagerResponse MoveToTrash(FileManagerDirectoryContent[] dataArray, string userId, String virtualConnection, string virtualUser)
184 | {
185 | string jsonPath = virtualUser + "\\trash.json";
186 | string jsonData = System.IO.File.ReadAllText(jsonPath);
187 | List DeletedFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
188 | PhysicalFileProvider trashOperation = new PhysicalFileProvider();
189 | string root = virtualConnection + "\\" + userId;
190 | trashOperation.RootFolder(root);
191 | List deletedFiles = new List();
192 | foreach (FileManagerDirectoryContent data in dataArray)
193 | {
194 | string fileLocation = "/Files" + data.FilterPath;
195 | DateTime deleteTime = DateTime.Now;
196 | string container = deleteTime.ToFileTimeUtc().ToString();
197 | string trashPath = "/Trash/" + container;
198 | Directory.CreateDirectory(root + trashPath);
199 | FileManagerResponse response = trashOperation.Move(fileLocation, trashPath, new string[] { data.Name }, null, null, null);
200 | if ((response.Error == null))
201 | {
202 | TrashContents deletedFile = new TrashContents()
203 | {
204 | Container = container,
205 | Data = data,
206 | DateDeleted = deleteTime,
207 | Name = data.Name,
208 | Path = data.FilterPath
209 | };
210 | deletedFile.Data.DateModified = deletedFile.DateDeleted;
211 | deletedFile.Data.Id = deletedFile.Container;
212 | DeletedFiles.Add(deletedFile);
213 | deletedFiles.Add(response.Files.First());
214 | }
215 | }
216 | jsonData = JsonConvert.SerializeObject(DeletedFiles);
217 | System.IO.File.WriteAllText(jsonPath, jsonData);
218 | return new FileManagerResponse() { Files = deletedFiles };
219 | }
220 | [Route("Upload")]
221 | public IActionResult Upload(string path, IList uploadFiles, string action)
222 | {
223 | #if Publish
224 | //Restrict the upload functionality for publish settings
225 | Response.Clear();
226 | Response.ContentType = "application/json; charset=utf-8";
227 | Response.StatusCode = 403;
228 | Response.HttpContext.Features.Get().ReasonPhrase = "The upload functionality is restricted in this online demo. To test this demo application with upload functionality, please download the source code from the GitHub location (https://github.com/syncfusion/blazor-showcase-document-explorer) and run it.";
229 | return Content("The upload functionality is restricted in this online demo. To test this demo application with upload functionality, please download the source code from the GitHub location (https://github.com/syncfusion/blazor-showcase-document-explorer) and run it.");
230 | #else
231 | string connectionId = HttpContext.Session.GetString("ConnectionId");
232 |
233 | if (string.IsNullOrEmpty(connectionId))
234 | {
235 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
236 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
237 | }
238 | FileManagerResponse uploadResponse;
239 | PhysicalFileProvider uploadOperation = new PhysicalFileProvider();
240 | string basePath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId;
241 | string userID = this.basePath + "wwwroot\\VirtualConnections\\" + connectionId + "\\Files";
242 | uploadOperation.RootFolder(userID);
243 | uploadResponse = operation.Upload(path, uploadFiles, action, basePath, null);
244 | if (uploadResponse.Error != null)
245 | {
246 | Response.Clear();
247 | Response.ContentType = "application/json; charset=utf-8";
248 | Response.StatusCode = Convert.ToInt32(uploadResponse.Error.Code);
249 | Response.HttpContext.Features.Get().ReasonPhrase = uploadResponse.Error.Message;
250 | }
251 | return Content("");
252 | #endif
253 | }
254 |
255 | [Route("Download")]
256 | public IActionResult Download(string downloadInput)
257 | {
258 | FileManagerDirectoryContent args = JsonConvert.DeserializeObject(downloadInput);
259 | FileManagerDirectoryContent[] items = args.Data;
260 | string[] names = args.Names;
261 | for (var i = 0; i < items.Length; i++)
262 | {
263 | names[i] = ((items[i].FilterPath + items[i].Name).Substring(1));
264 | }
265 | return operation.Download("/", names);
266 | }
267 |
268 | [Route("ToggleStarred")]
269 | public IActionResult ToggleStarred([FromBody] FileManagerCustomContent args)
270 | {
271 | string connectionId = HttpContext.Session.GetString("ConnectionId");
272 |
273 | if (string.IsNullOrEmpty(connectionId))
274 | {
275 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
276 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
277 | }
278 | string basePath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId +"\\User";
279 | string jsonPath = basePath + "\\star.json";
280 | StreamReader reader = new StreamReader(jsonPath);
281 | string jsonData = reader.ReadToEnd();
282 | reader.Dispose();
283 | List starredFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
284 | string path = args.Path.Replace(Path.DirectorySeparatorChar, '/');
285 | if (args.Starred && !starredFiles.Contains(path))
286 | {
287 | starredFiles.Add(path);
288 | }
289 | else if (!args.Starred && starredFiles.Contains(path))
290 | {
291 | starredFiles.Remove(path);
292 | }
293 | jsonData = JsonConvert.SerializeObject(starredFiles);
294 | System.IO.File.WriteAllText(jsonPath, jsonData);
295 | return Content("");
296 | }
297 |
298 | [Route("GetImage")]
299 | public IActionResult GetImage(FileManagerDirectoryContent args)
300 | {
301 | return this.operation.GetImage(args.Path, args.Id, false, null, null);
302 | }
303 |
304 | private void CopyFolder(string source, string destination)
305 | {
306 | if (!Directory.Exists(destination))
307 | {
308 | Directory.CreateDirectory(destination);
309 | }
310 |
311 | foreach (var file in Directory.EnumerateFiles(source))
312 | {
313 | var dest = Path.Combine(destination, Path.GetFileName(file));
314 | System.IO.File.Copy(file, dest);
315 | }
316 |
317 | foreach (var folder in Directory.EnumerateDirectories(source))
318 | {
319 | var dest = Path.Combine(destination, Path.GetFileName(folder));
320 | CopyFolder(folder, dest);
321 | }
322 | }
323 |
324 | public class FileManagerCustomContent : FileManagerDirectoryContent
325 | {
326 | public string RootType { get; set; }
327 |
328 | //Custom parameter inidicating starred files
329 | public bool Starred { get; set; }
330 | }
331 | public class FileResponse
332 | {
333 | public FileManagerDirectoryContent CWD { get; set; }
334 |
335 | public IEnumerable Files { get; set; }
336 |
337 | public ErrorDetails Error { get; set; }
338 |
339 | public FileDetails Details { get; set; }
340 |
341 | }
342 | public class TrashContents
343 | {
344 | public string Container { get; set; }
345 | public DateTime DateDeleted { get; set; }
346 | public string Path { get; set; }
347 | public string Name { get; set; }
348 | public FileManagerDirectoryContent Data { get; set; }
349 | }
350 | }
351 | }
--------------------------------------------------------------------------------
/server/Controllers/PresentationController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Mvc;
8 | using DocumentExplorer.Models.FileManager;
9 | using Syncfusion.Pdf;
10 | using Syncfusion.Presentation;
11 | using Syncfusion.PresentationRenderer;
12 |
13 | namespace DocumentExplorer.Controllers
14 | {
15 | [Route("api/[controller]")]
16 | [ApiController]
17 | public class PresentationController : ControllerBase
18 | {
19 | private string basePath;
20 | private string baseLocation;
21 | private IWebHostEnvironment _hostingEnvironment;
22 | public PresentationController(IWebHostEnvironment hostingEnvironment)
23 | {
24 | _hostingEnvironment = hostingEnvironment;
25 | basePath = _hostingEnvironment.ContentRootPath;
26 | baseLocation = basePath + "\\wwwroot\\";
27 | }
28 |
29 | [Route("ConvertToPDF")]
30 | public string[] ConvertToPDF([FromBody] FileManagerDirectoryContent args)
31 | {
32 | string fileLocation = this.baseLocation + args.Path.Replace("/", "\\");
33 | // If document get open from zip file, we have maintained the extracted document path in TargetPath property.
34 | if (args.TargetPath != null)
35 | fileLocation = args.TargetPath;
36 | List returnArray = new List();
37 | using FileStream fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read);
38 | //Open the existing presentation
39 | IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fs);
40 | //Convert the PowerPoint document to PDF document.
41 | PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);
42 | //Save the document as a stream and retrun the stream
43 | MemoryStream stream = new MemoryStream();
44 | //Save the created PowerPoint document to MemoryStream
45 | pdfDocument.Save(stream);
46 | stream.Position = 0;
47 | returnArray.Add("data:application/pdf;base64," + Convert.ToBase64String(stream.ToArray()));
48 | //Dispose the document objects.
49 | presentation.Dispose();
50 | pdfDocument.Dispose();
51 | stream.Dispose();
52 | return returnArray.ToArray();
53 |
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/server/Controllers/PreviewController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Drawing;
4 | using System.Collections.Generic;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Mvc;
7 | //File Manager's base functions are available in the below namespace
8 | using DocumentExplorer.Models.FileManager;
9 | //File Manager's operations are available in the below namespace
10 | using DocumentExplorer.Data;
11 | using DocIO = Syncfusion.DocIO.DLS;
12 | using Syncfusion.DocIORenderer;
13 | using Syncfusion.Pdf;
14 | using Syncfusion.Blazor.SfPdfViewer;
15 | using Syncfusion.Presentation;
16 | using Syncfusion.PresentationRenderer;
17 | using DocumentExplorer.Models;
18 | using SkiaSharp;
19 | using Microsoft.AspNetCore.Http;
20 |
21 | namespace DocumentExplorer.Controllers
22 | {
23 | [Route("api/[controller]")]
24 | [ApiController]
25 | public class PreviewController : ControllerBase
26 | {
27 | private PhysicalFileProvider operation;
28 | private string basePath;
29 | public PreviewController(IWebHostEnvironment hostingEnvironment)
30 | {
31 | basePath = hostingEnvironment.ContentRootPath;
32 | operation = new PhysicalFileProvider();
33 | operation.RootFolder(this.basePath + "\\wwwroot\\VirtualConnections\\"); // Data\\Files denotes in which files and folders are available.
34 | }
35 |
36 | [Route("GetPreview")]
37 | public string GetPreview([FromBody] FileManagerDirectoryContent args)
38 | {
39 | string connectionId = HttpContext.Session.GetString("ConnectionId");
40 |
41 | if (string.IsNullOrEmpty(connectionId))
42 | {
43 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
44 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
45 | }
46 | string baseFolder = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId + "\\Files";
47 | this.operation.RootFolder(baseFolder);
48 | try
49 | {
50 | String fullPath = baseFolder + args.Path;
51 | string extension = Path.GetExtension(fullPath);
52 | Stream imageStream = null;
53 | if (extension == Constants.Pdf)
54 | {
55 | try
56 | {
57 | // FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
58 | // SfPdfViewer2 pdfExportImage = new SfPdfViewer2();
59 | // //Loads the PDF document
60 | // pdfExportImage.LoadAsync(fileStream);
61 | // //Exports the PDF document pages into images
62 | // SkiaSharp.SKBitmap[] skBitmaps = pdfExportImage.ExportAsImage(0, 0);
63 | //System.Drawing.Bitmap[] bitmapImages = new System.Drawing.Bitmap[skBitmaps.Length];
64 |
65 | //for (int i = 0; i < skBitmaps.Length; i++)
66 | //{
67 | // using (SKImage skImage = SKImage.FromBitmap(skBitmaps[i]))
68 | // using (SKData skData = skImage.Encode(SKEncodedImageFormat.Png, 100))
69 | // using (System.IO.MemoryStream stream = new System.IO.MemoryStream(skData.ToArray()))
70 | // {
71 | // bitmapImages[i] = new System.Drawing.Bitmap(stream);
72 | // }
73 | //}
74 | //imageStream = new MemoryStream();
75 | //bitmapImages[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
76 | // imageStream.Position = 0;
77 | // pdfExportImage.Dispose();
78 | // fileStream.Close();
79 | }
80 | catch
81 | {
82 | imageStream = null;
83 | }
84 | }
85 | else if (extension == Constants.Docx || extension == Constants.Rtf || extension == Constants.Doc || extension == Constants.Txt)
86 | {
87 | try
88 | {
89 | //FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
90 | ////Loads file stream into Word document
91 | //DocIO.WordDocument document = new DocIO.WordDocument(fileStream, GetDocIOFormatType(extension));
92 | //fileStream.Dispose();
93 | ////Instantiation of DocIORenderer for Word to PDF conversion
94 | //DocIORenderer render = new DocIORenderer();
95 | ////Converts Word document into PDF document
96 | //PdfDocument pdfDocument = render.ConvertToPDF(document);
97 | ////Releases all resources used by the Word document and DocIO Renderer objects
98 | //render.Dispose();
99 | //document.Dispose();
100 | ////Saves the PDF file
101 | //MemoryStream outputStream = new MemoryStream();
102 | //pdfDocument.Save(outputStream);
103 | //outputStream.Position = 0;
104 | ////Closes the instance of PDF document object
105 | //pdfDocument.Close();
106 |
107 | //SfPdfViewer2 pdfExportImage = new SfPdfViewer2();
108 | ////Loads the PDF document
109 | //pdfExportImage.LoadAsync(outputStream);
110 | ////Exports the PDF document pages into images
111 | //SKBitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, 0);
112 | //Bitmap[] bitmapImages = new Bitmap[bitmapimage.Length];
113 |
114 | //for (int i = 0; i < bitmapimage.Length; i++)
115 | //{
116 | // using (SKImage skImage = SKImage.FromBitmap(bitmapimage[i]))
117 | // using (SKData skData = skImage.Encode(SKEncodedImageFormat.Png, 100))
118 | // using (System.IO.MemoryStream stream = new System.IO.MemoryStream(skData.ToArray()))
119 | // {
120 | // bitmapImages[i] = new Bitmap(stream);
121 | // }
122 | //}
123 |
124 | //imageStream = new MemoryStream();
125 | //bitmapImages[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
126 | //imageStream.Position = 0;
127 |
128 | //fileStream.Close();
129 | }
130 | catch
131 | {
132 | imageStream = null;
133 | }
134 | }
135 | else if (extension == Constants.Pptx)
136 | {
137 | try
138 | {
139 | IPresentation presentation = Presentation.Open(fullPath);
140 | //Initialize PresentationRenderer for image conversion
141 | presentation.PresentationRenderer = new PresentationRenderer();
142 | //Convert the first slide to image
143 | imageStream = presentation.Slides[0].ConvertToImage(ExportImageFormat.Png);
144 | presentation.Dispose();
145 | }
146 | catch
147 | {
148 | imageStream = null;
149 | }
150 | }
151 | if (imageStream != null)
152 | {
153 | byte[] bytes = new byte[imageStream.Length];
154 | imageStream.Read(bytes);
155 | string base64 = Convert.ToBase64String(bytes);
156 | return "data:image/png;base64, " + base64;
157 | }
158 | else
159 | {
160 | return "Error";
161 | }
162 | }
163 | catch
164 | {
165 | return "Error";
166 | }
167 | }
168 |
169 | private Syncfusion.DocIO.FormatType GetDocIOFormatType(string format)
170 | {
171 | if (string.IsNullOrEmpty(format))
172 | throw new NotSupportedException("DocumentEditor does not support this file format.");
173 | switch (format.ToLower())
174 | {
175 | case Constants.Dotx:
176 | case Constants.Docx:
177 | case Constants.Docm:
178 | case Constants.Dotm:
179 | return Syncfusion.DocIO.FormatType.Docx;
180 | case Constants.Dot:
181 | case Constants.Doc:
182 | return Syncfusion.DocIO.FormatType.Doc;
183 | case Constants.Rtf:
184 | return Syncfusion.DocIO.FormatType.Rtf;
185 | case Constants.Txt:
186 | return Syncfusion.DocIO.FormatType.Txt;
187 | case Constants.Xml:
188 | return Syncfusion.DocIO.FormatType.WordML;
189 | case Constants.Html:
190 | return Syncfusion.DocIO.FormatType.Html;
191 | default:
192 | throw new NotSupportedException("DocumentEditor does not support this file format.");
193 | }
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/server/Controllers/SharedFilesController.cs:
--------------------------------------------------------------------------------
1 | using DocumentExplorer.Shared;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System;
4 | using System.Collections.Generic;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.AspNetCore.Http.Features;
8 | //File Manager's base functions are available in the below namespace
9 | using DocumentExplorer.Models.FileManager;
10 | //File Manager's operations are available in the below namespace
11 | using DocumentExplorer.Data;
12 | using Newtonsoft.Json;
13 | using System.Linq;
14 | using System.Threading.Tasks;
15 | using System.IO;
16 | using Syncfusion.DocIO.DLS;
17 | using Syncfusion.DocIORenderer;
18 | using Syncfusion.Blazor.SfPdfViewer;
19 | using Syncfusion.Pdf;
20 | using Syncfusion.Presentation;
21 | using Syncfusion.PresentationRenderer;
22 | using System.Drawing;
23 | using Microsoft.AspNetCore.Cors;
24 | using DocumentExplorer.Models;
25 | using SkiaSharp;
26 |
27 | namespace DocumentExplorer.Controllers
28 | {
29 | [Route("api/[controller]")]
30 | [EnableCors("AllowAllOrigins")]
31 | public class SharedFilesController : ControllerBase
32 | {
33 | private PhysicalFileProvider operation;
34 | private string basePath;
35 | public SharedFilesController(IWebHostEnvironment hostingEnvironment)
36 | {
37 | this.basePath = hostingEnvironment.ContentRootPath;
38 | this.operation = new PhysicalFileProvider();
39 | this.operation.RootFolder(this.basePath + "\\wwwroot\\SharedFiles"); // Data\\Files denotes in which files and folders are available.
40 | }
41 |
42 | // Processing the File Manager operations
43 | [Route("FileOperations")]
44 | public object FileOperations([FromBody] FileManagerFilterContent args)
45 | {
46 | if (args.Path == "/Files/")
47 | {
48 | args.Path = "/";
49 | }
50 | switch (args.Action)
51 | {
52 | // Add your custom action here
53 | case "read":
54 | // Path - Current path; ShowHiddenItems - Boolean value to show/hide hidden items
55 | return this.operation.ToCamelCase(this.operation.GetFiles(args.Path, args.ShowHiddenItems));
56 | case "details":
57 | // Path - Current path where details of file/folder is requested; Name - Names of the requested folders
58 | return this.operation.ToCamelCase(this.operation.Details(args.Path, args.Names));
59 | case "create":
60 | FileManagerResponse createresponse = new FileManagerResponse();
61 | createresponse.Error = new ErrorDetails() { Code = "401", Message = "Restricted to perform this action" };
62 | return this.operation.ToCamelCase(createresponse);
63 | case "search":
64 | // Path - Current path where the search is performed; SearchString - String typed in the searchbox; CaseSensitive - Boolean value which specifies whether the search must be casesensitive
65 | return this.operation.ToCamelCase(this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive));
66 | case "delete":
67 | case "copy":
68 | case "move":
69 | case "rename":
70 | FileManagerResponse renameresponse = new FileManagerResponse();
71 | renameresponse.Error = new ErrorDetails() { Code = "401", Message = "Restricted to perform this action" };
72 | return this.operation.ToCamelCase(renameresponse);
73 | }
74 | return null;
75 | }
76 |
77 | [Route("Download")]
78 | public IActionResult Download(string downloadInput)
79 | {
80 |
81 | FileManagerFilterContent args = JsonConvert.DeserializeObject(downloadInput);
82 | FileManagerDirectoryContent[] items = args.Data;
83 | string[] names = args.Names;
84 | for (var i = 0; i < items.Length; i++)
85 | {
86 | names[i] = ((items[i].FilterPath + items[i].Name).Substring(1));
87 | }
88 | return operation.Download("/", names);
89 | }
90 |
91 |
92 | [Route("GetImage")]
93 | public IActionResult GetImage(FileManagerFilterContent args)
94 | {
95 | return this.operation.GetImage(args.Path, args.Id, false, null, null);
96 | }
97 | [Route("GetPreviewImage")]
98 | public IActionResult GetPreviewImage(FileManagerFilterContent args)
99 | {
100 | string baseFolder = this.basePath + "\\wwwroot\\SharedFiles";
101 |
102 | try
103 | {
104 | String fullPath = baseFolder + args.Path;
105 | string extension = Path.GetExtension(fullPath);
106 | Stream imageStream = null;
107 |
108 | if (extension == Constants.Pdf)
109 | {
110 | //FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
111 | //SfPdfViewer2 pdfExportImage = new SfPdfViewer2();
112 |
113 | //// Load the PDF document
114 | //pdfExportImage.LoadAsync(fileStream);
115 |
116 | //// Export the PDF document pages as SkiaSharp bitmaps
117 | //SkiaSharp.SKBitmap[] skBitmaps = pdfExportImage.ExportAsImage(0, 0);
118 |
119 | //if (skBitmaps.Length > 0)
120 | //{
121 | // // Encode the first page as PNG using SkiaSharp
122 | // using (SKImage skImage = SKImage.FromBitmap(skBitmaps[0]))
123 | // using (SKData skData = skImage.Encode(SKEncodedImageFormat.Png, 100))
124 | // {
125 | // imageStream = new MemoryStream(skData.ToArray());
126 | // imageStream.Position = 0;
127 | // }
128 | //}
129 |
130 | //// Clean up resources
131 | //pdfExportImage.Dispose();
132 | //fileStream.Close();
133 | }
134 | else if (extension == Constants.Docx || extension == Constants.Rtf || extension == Constants.Doc)
135 | {
136 | //FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
137 | ////Loads file stream into Word document
138 | //WordDocument document = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic);
139 | //fileStream.Dispose();
140 | ////Instantiation of DocIORenderer for Word to PDF conversion
141 | //DocIORenderer render = new DocIORenderer();
142 | ////Converts Word document into PDF document
143 | //PdfDocument pdfDocument = render.ConvertToPDF(document);
144 | ////Releases all resources used by the Word document and DocIO Renderer objects
145 | //render.Dispose();
146 | //document.Dispose();
147 | ////Saves the PDF file
148 | //MemoryStream outputStream = new MemoryStream();
149 | //pdfDocument.Save(outputStream);
150 | //outputStream.Position = 0;
151 | ////Closes the instance of PDF document object
152 | //pdfDocument.Close();
153 |
154 | //SfPdfViewer2 pdfExportImage = new SfPdfViewer2();
155 | ////Loads the PDF document
156 | //pdfExportImage.LoadAsync(outputStream);
157 | ////Exports the PDF document pages into images
158 | //SkiaSharp.SKBitmap[] skBitmaps = pdfExportImage.ExportAsImage(0, 0);
159 | //System.Drawing.Bitmap[] bitmapImages = new System.Drawing.Bitmap[skBitmaps.Length];
160 |
161 | //for (int i = 0; i < skBitmaps.Length; i++)
162 | //{
163 | // using (SKImage skImage = SKImage.FromBitmap(skBitmaps[i]))
164 | // using (SKData skData = skImage.Encode(SKEncodedImageFormat.Png, 100))
165 | // using (System.IO.MemoryStream stream = new System.IO.MemoryStream(skData.ToArray()))
166 | // {
167 | // bitmapImages[i] = new System.Drawing.Bitmap(stream);
168 | // }
169 | //}
170 | //imageStream = new MemoryStream();
171 | //bitmapImages[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
172 | //imageStream.Position = 0;
173 |
174 | //fileStream.Close();
175 | }
176 | else if (extension == Constants.Pptx)
177 | {
178 | IPresentation presentation = Presentation.Open(fullPath);
179 | //Initialize PresentationRenderer for image conversion
180 | presentation.PresentationRenderer = new PresentationRenderer();
181 | //Convert the first slide to image
182 | imageStream = presentation.Slides[0].ConvertToImage(ExportImageFormat.Png);
183 | presentation.Dispose();
184 | }
185 | FileStreamResult fileStreamResult = new FileStreamResult(imageStream, "APPLICATION/octet-stream");
186 | return fileStreamResult;
187 | }
188 | catch
189 | {
190 | return null;
191 | }
192 | }
193 |
194 |
195 | public class FileManagerFilterContent : FileManagerDirectoryContent
196 | {
197 | public string RootType { get; set; }
198 | }
199 |
200 | }
201 | }
--------------------------------------------------------------------------------
/server/Controllers/TrashController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Http;
8 | using Microsoft.AspNetCore.Mvc;
9 | using Newtonsoft.Json;
10 | using DocumentExplorer.Models.FileManager;
11 | using DocumentExplorer.Data;
12 | using System.Text.RegularExpressions;
13 | using Microsoft.AspNetCore.Cors;
14 |
15 | namespace DocumentExplorer.Controllers
16 | {
17 | [Route("api/[controller]")]
18 | [EnableCors("AllowAllOrigins")]
19 | public class TrashController : ControllerBase
20 | {
21 | private PhysicalFileProvider operation;
22 | private string basePath;
23 | private string baseLocation;
24 |
25 | public TrashController(IWebHostEnvironment hostingEnvironment)
26 | {
27 | this.basePath = hostingEnvironment.ContentRootPath;
28 | this.baseLocation = this.basePath + "\\wwwroot\\VirtualConnections\\";
29 | this.operation = new PhysicalFileProvider();
30 | }
31 |
32 | // Processing the File Manager operations
33 | [Route("FileOperations")]
34 | public object FileOperations([FromBody] ReadArgs args)
35 | {
36 | if (args.Path == "/Files/")
37 | {
38 | args.Path = "/";
39 | }
40 | try
41 | {
42 | switch (args.Action)
43 | {
44 | // Add your custom action here
45 | case "read":
46 | // Path - Current path; ShowHiddenItems - Boolean value to show/hide hidden items
47 | return this.operation.ToCamelCase(this.GetFiles());
48 | case "search":
49 | // Path - Current path where the search is performed; SearchString - String typed in the searchbox; CaseSensitive - Boolean value which specifies whether the search must be casesensitive
50 | //return this.operation.ToCamelCase(this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive));
51 | return this.operation.ToCamelCase(this.SearchFiles(args.SearchString,args.CaseSensitive));
52 | case "details":
53 | // Path - Current path where details of file/folder is requested; Name - Names of the requested folders
54 | return this.operation.ToCamelCase(this.GetDetails(args.Data));
55 | case "delete":
56 | // Path - Current path where of the folder to be deleted; Names - Name of the files to be deleted
57 | return this.operation.ToCamelCase(this.DeleteFiles(args.Data));
58 | case "rename":
59 | case "create":
60 | case "move":
61 | case "copy":
62 | // Path - Current path of the renamed file; Name - Old file name; NewName - New file name
63 | // return this.operation.ToCamelCase(this.operation.Rename(args.Path, args.Name, args.NewName));
64 | FileManagerResponse response = new FileManagerResponse();
65 | response.Error = new ErrorDetails() { Code = "401", Message = "Restore file to perform this action" };
66 | return this.operation.ToCamelCase(response);
67 | }
68 | return null;
69 | }
70 | catch (IOException e)
71 | {
72 | throw e;
73 | }
74 | }
75 |
76 | public FileManagerResponse GetFiles()
77 | {
78 | string connectionId = HttpContext.Session.GetString("ConnectionId");
79 |
80 | if (string.IsNullOrEmpty(connectionId))
81 | {
82 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
83 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
84 | }
85 | FileManagerResponse readResponse = new FileManagerResponse();
86 | FileManagerDirectoryContent cwd = new FileManagerDirectoryContent();
87 | String fullPath = (this.baseLocation + connectionId + "/Trash");
88 | DirectoryInfo directory = new DirectoryInfo(fullPath);
89 | cwd.Name = "Trash";
90 | cwd.Size = 0;
91 | cwd.IsFile = false;
92 | cwd.DateModified = directory.LastWriteTime;
93 | cwd.DateCreated = directory.CreationTime;
94 | cwd.HasChild = false;
95 | cwd.Type = directory.Extension;
96 | cwd.FilterPath = "/";
97 | cwd.Permission = null;
98 | readResponse.CWD = cwd;
99 | string jsonPath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId +"\\User\\trash.json";
100 | string jsonData = System.IO.File.ReadAllText(jsonPath);
101 | List DeletedFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
102 | List files = new List();
103 | foreach (TrashContents file in DeletedFiles)
104 | {
105 | files.Add(file.Data);
106 | }
107 | readResponse.Files = files;
108 | return readResponse;
109 | }
110 | public FileManagerResponse GetDetails(FileManagerDirectoryContent[] files)
111 | {
112 | string connectionId = HttpContext.Session.GetString("ConnectionId");
113 |
114 | if (string.IsNullOrEmpty(connectionId))
115 | {
116 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
117 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
118 | }
119 | this.operation.RootFolder(this.baseLocation + connectionId + "\\Trash");
120 | FileManagerResponse response;
121 | string[] names = new string[files.Length];
122 | string responseName = "";
123 | int index = 0;
124 | foreach (FileManagerDirectoryContent file in files)
125 | {
126 | names[index] = file.Id;
127 | index++;
128 | responseName = (responseName == "") ? file.Name : (responseName + ", " + file.Name);
129 | }
130 | response = this.operation.Details("/", names);
131 | response.Details.Name = responseName;
132 | response.Details.Location = "Trash";
133 | return response;
134 | }
135 | public FileManagerResponse DeleteFiles(FileManagerDirectoryContent[] files)
136 | {
137 | string connectionId = HttpContext.Session.GetString("ConnectionId");
138 |
139 | if (string.IsNullOrEmpty(connectionId))
140 | {
141 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
142 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
143 | }
144 | this.operation.RootFolder(this.baseLocation + connectionId);
145 | string jsonPath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId + "\\User\\trash.json";
146 | string jsonData = System.IO.File.ReadAllText(jsonPath);
147 | List responseFiles =new List();
148 | List DeletedFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
149 | foreach (FileManagerDirectoryContent file in files)
150 | {
151 | TrashContents trashFile = DeletedFiles.Find(x => (x.Container.Equals(file.Id)));
152 | string trashPath = "/Trash/" + trashFile.Container;
153 | DeleteDirectory(this.baseLocation + connectionId + trashPath);
154 | responseFiles.Add(trashFile.Data);
155 | DeletedFiles.Remove(trashFile);
156 | }
157 | jsonData = JsonConvert.SerializeObject(DeletedFiles);
158 | System.IO.File.WriteAllText(jsonPath, jsonData);
159 | return new FileManagerResponse() { Files = responseFiles };
160 | }
161 | [Route("EmptyTrash")]
162 | public IActionResult EmptyTrash()
163 | {
164 | string connectionId = HttpContext.Session.GetString("ConnectionId");
165 |
166 | if (string.IsNullOrEmpty(connectionId))
167 | {
168 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
169 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
170 | }
171 | string jsonPath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId + "\\User\\trash.json";
172 | string jsonData ="";
173 | string[] dirs = Directory.GetDirectories(this.baseLocation + connectionId);
174 | foreach (string dir in dirs)
175 | {
176 | DeleteDirectory(dir);
177 | }
178 | System.IO.File.WriteAllText(jsonPath, jsonData);
179 | return Content("");
180 | }
181 |
182 | [Route("Restore")]
183 | public IActionResult Restore([FromBody] FileManagerDirectoryContent[] files)
184 | {
185 | string connectionId = HttpContext.Session.GetString("ConnectionId");
186 |
187 | if (string.IsNullOrEmpty(connectionId))
188 | {
189 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
190 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
191 | }
192 | this.operation.RootFolder(this.baseLocation + connectionId);
193 | string jsonPath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId + "\\User\\trash.json";
194 | string jsonData = System.IO.File.ReadAllText(jsonPath);
195 | string responseString = "";
196 | List DeletedFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
197 | foreach (FileManagerDirectoryContent file in files)
198 | {
199 | TrashContents trashFile = DeletedFiles.Find(x => (x.Container.Equals(file.Id)));
200 | string fileLocation = "/Files" + trashFile.Path;
201 | string trashPath = "/Trash/" + trashFile.Container;
202 | FileManagerResponse response = this.operation.Move(trashPath, fileLocation, new string[] { trashFile.Name }, new string[] { trashFile.Name }, null, null);
203 | if ((response.Error == null))
204 | {
205 | DeleteDirectory(this.baseLocation + connectionId + trashPath);
206 | DeletedFiles.Remove(trashFile);
207 | responseString = "Restored";
208 | }
209 | else
210 | {
211 | responseString = "Restore Failed";
212 | }
213 | }
214 | jsonData = JsonConvert.SerializeObject(DeletedFiles);
215 | System.IO.File.WriteAllText(jsonPath, jsonData);
216 | return Content(responseString);
217 | }
218 |
219 | public FileManagerResponse SearchFiles(string value, bool caseSensitive)
220 | {
221 | string connectionId = HttpContext.Session.GetString("ConnectionId");
222 |
223 | if (string.IsNullOrEmpty(connectionId))
224 | {
225 | connectionId = Guid.NewGuid().ToString(); // Generate a new unique identifier
226 | HttpContext.Session.SetString("ConnectionId", connectionId); // Store it in session
227 | }
228 | this.operation.RootFolder(this.baseLocation + connectionId);
229 | string jsonPath = this.basePath + "\\wwwroot\\VirtualConnections\\" + connectionId + "\\User\\trash.json";
230 | string jsonData = System.IO.File.ReadAllText(jsonPath);
231 | List DeletedFiles = JsonConvert.DeserializeObject>(jsonData) ?? new List();
232 | List searchFiles = DeletedFiles.FindAll(x => new Regex(WildcardToRegex(value), (caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase)).IsMatch(x.Name));
233 | List data = new List();
234 | foreach(TrashContents file in searchFiles) {
235 | data.Add(file.Data);
236 | }
237 | return new FileManagerResponse() { Files=data} ;
238 | }
239 | public virtual string WildcardToRegex(string value)
240 | {
241 | return "^" + Regex.Escape(value).Replace(@"\*", ".*").Replace(@"\?", ".") + "$";
242 | }
243 | public void DeleteDirectory(string path)
244 | {
245 |
246 | try
247 | {
248 | string[] files = Directory.GetFiles(path);
249 | string[] dirs = Directory.GetDirectories(path);
250 | foreach (string file in files)
251 | {
252 | System.IO.File.SetAttributes(file, FileAttributes.Normal);
253 | System.IO.File.Delete(file);
254 | }
255 | foreach (string dir in dirs)
256 | {
257 | DeleteDirectory(dir);
258 | }
259 | Directory.Delete(path, true);
260 | }
261 | catch (IOException e)
262 | {
263 | throw e;
264 | }
265 | }
266 | }
267 | public class TrashContents
268 | {
269 | public string Container { get; set; }
270 | public DateTime DateDeleted { get; set; }
271 | public string Path { get; set; }
272 | public string Name { get; set; }
273 | public FileManagerDirectoryContent Data { get; set; }
274 | }
275 |
276 | }
--------------------------------------------------------------------------------
/server/Controllers/ZipViewerController.cs:
--------------------------------------------------------------------------------
1 | using DocumentExplorer.Shared;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System;
4 | using System.Collections.Generic;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.AspNetCore.Http.Features;
8 | //File Manager's base functions are available in the below namespace
9 | using DocumentExplorer.Models.FileManager;
10 | //File Manager's operations are available in the below namespace
11 | using DocumentExplorer.Data;
12 | using Newtonsoft.Json;
13 | using System.Linq;
14 | using System.Threading.Tasks;
15 | using System.IO;
16 | using System.IO.Compression;
17 |
18 | namespace DocumentExplorer.Controllers
19 | {
20 | [Route("api/[controller]")]
21 | [ApiController]
22 | public class ZipViewerController : ControllerBase
23 | {
24 | private PhysicalFileProvider operation;
25 | private string tempDir;
26 | private string basePath;
27 | private string baseLocation;
28 | private IWebHostEnvironment _hostingEnvironment;
29 |
30 |
31 | public ZipViewerController(IWebHostEnvironment hostingEnvironment)
32 | {
33 | _hostingEnvironment = hostingEnvironment;
34 | this.basePath = _hostingEnvironment.ContentRootPath;
35 | this.baseLocation = this.basePath + "\\wwwroot\\";
36 | // Temprorary location to store content of the zip file
37 | // this.tempDir = this.basePath + "\\" + "tempZipStorage";
38 | this.tempDir = Path.GetTempPath() + "tempZipStorage";
39 | if (!Directory.Exists(this.tempDir))
40 | Directory.CreateDirectory(this.tempDir);
41 | this.operation = new PhysicalFileProvider();
42 | //this.operation.RootFolder(this.basePath + "\\wwwroot\\Files"); // Data\\Files denotes in which files and folders are available.
43 | this.operation.RootFolder(this.tempDir);
44 | }
45 |
46 | [Route("Root")]
47 | public string Root()
48 | {
49 | return this.tempDir;
50 | }
51 |
52 | // Processing the File Manager operations
53 | [Route("FileOperations")]
54 | public object FileOperations([FromBody] ReadArgs args)
55 | {
56 | try
57 | {
58 | switch (args.Action)
59 | {
60 | // Add your custom action here
61 | case "read":
62 | // Path - Current path; ShowHiddenItems - Boolean value to show/hide hidden items
63 | return this.operation.ToCamelCase(this.operation.GetFiles(args.Path, args.ShowHiddenItems));
64 | case "search":
65 | case "details":
66 | case "delete":
67 | case "copy":
68 | case "move":
69 | case "create":
70 | case "rename":
71 | FileManagerResponse response = new FileManagerResponse();
72 | response.Error = new ErrorDetails() { Code = "401", Message = "Extract the Zip file to perform this action" };
73 | return this.operation.ToCamelCase(response);
74 | }
75 | return null;
76 | }
77 | catch (IOException e)
78 | {
79 | throw e;
80 | }
81 | }
82 | [Route("ExtractZip")]
83 | public IActionResult ExtractZip([FromBody] FileManagerDirectoryContent args)
84 | {
85 | DeleteDirectoryContent();
86 | string zipLocation = this.baseLocation + args.Path;
87 | ZipFile.ExtractToDirectory(zipLocation, this.tempDir);
88 | return Content("Extracted");
89 | }
90 |
91 | public string Extract(string ZipPath)
92 | {
93 | try
94 | {
95 | DeleteDirectoryContent();
96 | string zipLocation = this.baseLocation + ZipPath;
97 | if (System.IO.File.Exists(zipLocation))
98 | {
99 | ZipFile.ExtractToDirectory(zipLocation, this.tempDir);
100 | return "Extracted";
101 | }
102 | else
103 | {
104 | return "PathNotFound";
105 | }
106 | }
107 | catch (IOException e)
108 | {
109 | throw e;
110 | }
111 | }
112 |
113 | public void DeleteDirectoryContent()
114 | {
115 | string path = tempDir;
116 | try
117 | {
118 | string[] files = Directory.GetFiles(path);
119 | string[] dirs = Directory.GetDirectories(path);
120 | foreach (string file in files)
121 | {
122 | System.IO.File.SetAttributes(file, FileAttributes.Normal);
123 | System.IO.File.Delete(file);
124 | }
125 | foreach (string dir in dirs)
126 | {
127 | DeleteDirectory(dir);
128 | }
129 | }
130 | catch (IOException e)
131 | {
132 | throw e;
133 | }
134 | }
135 | public void DeleteDirectory(string path)
136 | {
137 |
138 | try
139 | {
140 | string[] files = Directory.GetFiles(path);
141 | string[] dirs = Directory.GetDirectories(path);
142 | foreach (string file in files)
143 | {
144 | System.IO.File.SetAttributes(file, FileAttributes.Normal);
145 | System.IO.File.Delete(file);
146 | }
147 | foreach (string dir in dirs)
148 | {
149 | DeleteDirectory(dir);
150 | }
151 | Directory.Delete(path, true);
152 | }
153 | catch (IOException e)
154 | {
155 | throw e;
156 | }
157 | }
158 | }
159 | public class ReadArgs : FileManagerDirectoryContent
160 | {
161 | public string ZipPath { get; set; }
162 | }
163 | }
--------------------------------------------------------------------------------
/server/DocumentExplorer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | DocumentExplorer
6 | Debug;Release;Publish
7 |
8 |
9 |
10 | TRACE;Publish
11 |
12 |
13 |
14 | False
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Always
53 |
54 |
55 |
56 |
57 |
58 | Always
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/server/Models/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace DocumentExplorer.Models
7 | {
8 | public class Constants
9 | {
10 | public const string Zip = ".zip";
11 | public const string Pptx = ".pptx";
12 | public const string Pdf = ".pdf";
13 | public const string Docx = ".docx";
14 | public const string Doc = ".doc";
15 | public const string Rtf = ".rtf";
16 | public const string Txt = ".txt";
17 | public const string Dotx = ".dotx";
18 | public const string Docm = ".docm";
19 | public const string Dotm = ".dotm";
20 | public const string Dot = ".dot";
21 | public const string Xml = ".xml";
22 | public const string Html = ".html";
23 | public const string Bmp = ".bmp";
24 | public const string Dib = ".dib";
25 | public const string Jpg = ".jpg";
26 | public const string Jpeg = ".jpeg";
27 | public const string Jpe = ".jpe";
28 | public const string Jfif = ".jfif";
29 | public const string Gif = ".gif";
30 | public const string Tif = ".tif";
31 | public const string Tiff = ".tiff";
32 | public const string Png = ".png";
33 | public const string Ico = ".ico";
34 |
35 |
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/server/Models/FileManager/AccessDetails.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | #if EJ2_DNX
5 | using System.Web;
6 | #endif
7 |
8 | namespace DocumentExplorer.Models.FileManager
9 | {
10 | public class AccessDetails
11 | {
12 | public string Role { get; set; }
13 | public IEnumerable AccessRules { get; set; }
14 | }
15 |
16 | public class AccessRule
17 | {
18 | public Permission Copy { get; set; }
19 | public Permission Download { get; set; }
20 | public Permission Write { get; set; }
21 | public string Path { get; set; }
22 | public Permission Read { get; set; }
23 | public string Role { get; set; }
24 | public Permission WriteContents { get; set; }
25 | public Permission Upload { get; set; }
26 | public bool IsFile { get; set; }
27 | public string Message { get; set; }
28 | }
29 | public enum Permission
30 | {
31 | Allow,
32 | Deny
33 | }
34 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/AccessPermission.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace DocumentExplorer.Models.FileManager
6 | {
7 | public class AccessPermission
8 | {
9 | public bool Copy = true;
10 | public bool Download = true;
11 | public bool Write = true;
12 | public bool WriteContents = true;
13 | public bool Read = true;
14 | public bool Upload = true;
15 | public string Message = String.Empty;
16 | }
17 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/ErrorDetails.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | #if EJ2_DNX
5 | using System.Web;
6 | #endif
7 |
8 | namespace DocumentExplorer.Models.FileManager
9 | {
10 | public class ErrorDetails
11 | {
12 |
13 | public string Code { get; set; }
14 |
15 | public string Message { get; set; }
16 |
17 | public IEnumerable FileExists { get; set; }
18 | }
19 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/FileDetails.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DocumentExplorer.Models.FileManager
4 | {
5 | public class FileDetails
6 | {
7 | public string Name { get; set; }
8 | public string Location { get; set; }
9 | public bool IsFile { get; set; }
10 | public string Size { get; set; }
11 | public DateTime Created { get; set; }
12 | public DateTime Modified { get; set; }
13 | public bool MultipleFiles { get; set; }
14 | public AccessPermission Permission { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/server/Models/FileManager/FileManagerDirectoryContent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.AspNetCore.Http;
4 |
5 |
6 | namespace DocumentExplorer.Models.FileManager
7 | {
8 | public class FileManagerDirectoryContent
9 | {
10 | public string Path { get; set; }
11 |
12 | public string Action { get; set; }
13 |
14 | public string NewName { get; set; }
15 |
16 | public string[] Names { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public long Size { get; set; }
21 |
22 | public string PreviousName { get; set; }
23 |
24 | public DateTime DateModified { get; set; }
25 |
26 | public DateTime DateCreated { get; set; }
27 |
28 | public bool HasChild { get; set; }
29 |
30 | public bool IsFile { get; set; }
31 |
32 | public string Type { get; set; }
33 |
34 | public string Id { get; set; }
35 |
36 | public string FilterPath { get; set; }
37 |
38 | public string FilterId { get; set; }
39 |
40 | public string ParentId { get; set; }
41 |
42 | public string TargetPath { get; set; }
43 |
44 | public string[] RenameFiles { get; set; }
45 |
46 | public IList UploadFiles { get; set; }
47 |
48 | public bool CaseSensitive { get; set; }
49 |
50 | public string SearchString { get; set; }
51 |
52 | public bool ShowHiddenItems { get; set; }
53 |
54 | public FileManagerDirectoryContent[] Data { get; set; }
55 |
56 | public FileManagerDirectoryContent TargetData { get; set; }
57 |
58 | public AccessPermission Permission { get; set; }
59 | }
60 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/FileManagerParams.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | #if EJ2_DNX
5 | using System.Web;
6 | #else
7 | using Microsoft.AspNetCore.Http;
8 | #endif
9 |
10 | namespace DocumentExplorer.Models.FileManager
11 | {
12 | public class FileManagerParams
13 | {
14 | public string Name { get; set; }
15 |
16 | public string[] Names { get; set; }
17 |
18 | public string Path { get; set; }
19 |
20 | public string TargetPath { get; set; }
21 |
22 | public string NewName { get; set; }
23 |
24 | public object Date { get; set; }
25 | #if EJ2_DNX
26 | public IEnumerable FileUpload { get; set; }
27 | #else
28 | public IEnumerable FileUpload { get; set; }
29 |
30 | #endif
31 | public string[] ReplacedItemNames { get; set; }
32 | }
33 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/FileManagerResponse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | #if EJ2_DNX
5 | using System.Web;
6 | #endif
7 |
8 | namespace DocumentExplorer.Models.FileManager
9 | {
10 |
11 | public class FileManagerResponse
12 | {
13 | public FileManagerDirectoryContent CWD { get; set; }
14 | public IEnumerable Files { get; set; }
15 |
16 | public ErrorDetails Error { get; set; }
17 |
18 | public FileDetails Details { get; set; }
19 |
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/server/Models/FileManager/IFileProvider.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Serialization;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.IO.Compression;
7 | using System.Linq;
8 | using System.Text.RegularExpressions;
9 | using Microsoft.AspNetCore.Mvc;
10 | using Microsoft.AspNetCore.Http;
11 | using Microsoft.Net.Http.Headers;
12 |
13 | namespace DocumentExplorer.Models.FileManager
14 | {
15 | public interface IFileProvider
16 | {
17 |
18 | FileManagerResponse GetFiles(string path, bool showHiddenItems, params FileManagerDirectoryContent[] data);
19 | FileManagerResponse Create(string path, string name, params FileManagerDirectoryContent[] data);
20 |
21 | FileManagerResponse Details(string path, string[] names, params FileManagerDirectoryContent[] data);
22 |
23 | FileManagerResponse Delete(string path, string[] names, params FileManagerDirectoryContent[] data);
24 |
25 | FileManagerResponse Rename(string path, string name, string newName, bool replace = false, params FileManagerDirectoryContent[] data);
26 |
27 | FileManagerResponse Copy(string path, string targetPath, string[] names, string[] renameFiles, FileManagerDirectoryContent targetData, params FileManagerDirectoryContent[] data);
28 |
29 | FileManagerResponse Move(string path, string targetPath, string[] names, string[] renameFiles, FileManagerDirectoryContent targetData, params FileManagerDirectoryContent[] data);
30 |
31 | FileManagerResponse Search(string path, string searchString, bool showHiddenItems, bool caseSensitive, params FileManagerDirectoryContent[] data);
32 |
33 | FileStreamResult Download(string path, string[] names, params FileManagerDirectoryContent[] data);
34 | #if EJ2_DNX
35 | FileManagerResponse Upload(string path, IList uploadFiles, string action, params FileManagerDirectoryContent[] data);
36 | #else
37 | FileManagerResponse Upload(string path, IList uploadFiles, string action, string basePath, params FileManagerDirectoryContent[] data);
38 | #endif
39 |
40 | FileStreamResult GetImage(string path, string id, bool allowCompress, ImageSize size, params FileManagerDirectoryContent[] data);
41 |
42 | }
43 |
44 | }
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/server/Models/FileManager/IPhysicalFileProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using DocumentExplorer.Models.FileManager;
7 |
8 | using Microsoft.AspNetCore.Mvc;
9 | using Microsoft.AspNetCore.Http;
10 | using Microsoft.Net.Http.Headers;
11 |
12 |
13 | namespace DocumentExplorer.Models.FileManager
14 | {
15 | public interface IPhysicalFileProvider : IFileProvider
16 | {
17 | void RootFolder(string folderName);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/server/Models/FileManager/ImageSize.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | #if EJ2_DNX
5 | using System.Web;
6 | #endif
7 |
8 | namespace DocumentExplorer.Models.FileManager
9 | {
10 | public class ImageSize
11 | {
12 | public int Height { get; set; }
13 | public int Width { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/server/Models/ThumbnailImage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace DocumentExplorer.Models
7 | {
8 | public class ThumbnailImage
9 | {
10 | public string Src { get; set; }
11 | public int PageNumber { get; set; }
12 |
13 | public ThumbnailImage(int pageNumber, string src)
14 | {
15 | PageNumber = pageNumber;
16 | Src = src;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/server/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/server/Pages/About.razor:
--------------------------------------------------------------------------------
1 | @page "/about"
2 |
3 |
4 |
5 |
6 |
7 |
8 | This document explorer demo application showcases several Syncfusion Blazor UI components together in a real-world application scenario. You can explore the source code of this application and use it as a reference for integrating Syncfusion Blazor UI components into your applications.
9 |
10 |
List of Syncfusion Blazor UI components used in this sample