Hi,
I'm trying to get the "Initialize the File Manager" example from the "Getting Started" section located here
https://ej2.syncfusion.com/aspnetcore/documentation/file-manager/getting-started/
working for Razor Pages in ASP.NET Core 5.0
I'm currently stuck updating the FileOperations method to razor pages.
I tried changing the return type to ActionResult<string> but get the following error
InvalidOperationException: Unsupported handler method return type 'Microsoft.AspNetCore.Mvc.ActionResult`1[System.String]'.
Is it possible to get a Razor Pages example of this example?
Cheers
Hi Indhumathy,
Thankyou for the reply, im still having issues applying what you supplied me in my example, i've attached my example for you to review.
If you could take a look at what i have so far and let me know where im going wrong that would get great!
Regards,
Sean
I tried using the example you gave above which works fine. But when I try to add the code to a Razor Page in another application I get a network error consistently.
The only real difference is that the FileManager is located at /FileManager/Index instead of root site.
My file gets the following
|
<ejs-filemanager id="file" success="onSuccess" failure="onFailure">
<e-filemanager-ajaxsettings url="/FileManager/Index?handler=FileOperations" getImageUrl="/FileManager/Index?handler=GetImage" uploadUrl="/FileManager/Index?handler=Upload" downloadUrl="/FileManager/Index?handler=Download">
</e-filemanager-ajaxsettings>
</ejs-filemanager> |
That is what my filemanager looks like and it is giving the networkerror.
The following is the code in the file, I just copied and changed what was needed to move it to that folder.
Including the PhysicalFileProvider.cs file.
/FileManager/Index.cshtml file
<ejs-filemanager id="file" success="onSuccess" failure="onFailure">
<e-filemanager-ajaxsettings url="/FileManager/Index?handler=FileOperations" getImageUrl="/FileManager/Index?handler=GetImage" uploadUrl="/FileManager/Index?handler=Upload" downloadUrl="/FileManager/Index?handler=Download">
</e-filemanager-ajaxsettings>
</ejs-filemanager>
<script>
// File Manager's file onSuccess function
function onSuccess() {
console.log("Ajax request successful");
}
// File Manager's file onError function
function onFailure() {
console.log("Ajax request has failed");
}
</script>
/FileManager/Index.cshtml.cs
public PhysicalFileProviderTest operation;
public string basePath;
string root = "wwwroot\\Files";
public IndexModel(IHostingEnvironment hostingEnvironment)
{
this.basePath = hostingEnvironment.ContentRootPath;
this.operation = new PhysicalFileProviderTest();
this.operation.RootFolder(this.basePath + "\\" + this.root);
}
public IActionResult OnPostFileOperations([FromBody] FileManagerDirectoryContent args)
{
...
}
public IActionResult OnPostUpload(string path, IList<IFormFile> uploadFiles, string action)
{
...
}
public IActionResult OnPostDownload(string downloadInput)
{
...
}
// gets the image(s) from the given path\
public IActionResult OnGetGetImage(FileManagerDirectoryContent args)
{
...
}
Was this ever resolved? I'm literally trying the same thing and getting the same results. I downloaded the sample app and copied the code into my page and it still doesn't work. I get the XMLHttp error popup.
Hi Charles,
Based on the shared details, you were facing an issue in the FileManager component while checking the sample we shared three years ago. However, we have downloaded the same sample and tested it at our end without making any changes. The sample is running properly, and file operations are also working as expected without any issues on our end.
For your reference, we have attached the sample and screenshot.
Sample: Attached as a zip file.
Screenshot:
|
|
Please check and run the attached sample (navigate to the FileManager/Index), and if you are still facing any issues, could you replicate the issue in the attached sample or share a replicated sample along with video footage for our better understanding? This will help us provide you with a prompt solution. Kindly get back to us with the requested details.
Regards,
Prasanth Madhaiyan.
I finally got my filemanager partially working. In the end I had to add the attribute "
[IgnoreAntiforgeryToken]" to the pagemodel class and then the filemanager displayed the folders.
Everything seems to be working now except Download. The files are downloaded, but as soon as the operation is complete my app shuts down.
The download handler looks like this:
public IActionResult OnPostDownload(string downloadInput)
{
FileManagerDirectoryContent args = Newtonsoft.Json.JsonConvert.DeserializeObject<FileManagerDirectoryContent>(downloadInput);
var result = operation.Download(args.Path, args.Names);
return result;
}
Any help would be appre
Hi Charles,
Based on the shared code snippets for the download operation, we tested the functionality in both older and latest package versions. However, the download operation worked properly, and we were unable to replicate the reported application shutdown after the operation completed.
For your reference, we have attached the sample and video footage.
Sample and video: attached as a zip file.
Please check the attached sample. If the issue still persists on your end, kindly replicate the issue in the attached sample or share a sample where the issue can be reproduced. To provide you with a better solution, we need to replicate the issue on our end. Kindly get back to us with the requested details.
Regards,
Prasanth Madhaiyan.