Create Custom Actions for Double Click and Open from Context Menu

I'd like to create my own functions for some file types when the user attempts to open or double click.  Where do in the standard template is the code to intercept that user request?  I looked through the FileManagerController and PhysicalFileProvider class modules but didn't see an "Open" 


2 Replies


KR Keerthana Rajendran Syncfusion Team November 29, 2021 08:19 AM UTC

Hi John, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked with your query and suspect that your requirement is to call your own custom functions in the service provider when the user opens a file by double click or by context menu. To achieve this requirement, you can make use of the OnMenuClick event and OnFileOpen events of the File Manager component as shown in below code snippet. 
@using System.Text;  
@using Syncfusion.Blazor.FileManager; 
 
<div class="control-section"> 
    <SfFileManager TValue="FileManagerDirectoryContent"> 
        <FileManagerEvents TValue="FileManagerDirectoryContent" OnMenuClick="MenuClick" OnFileOpen="Open"></FileManagerEvents> 
        <FileManagerAjaxSettings Url="/api/FileManager/FileOperations" 
                                 UploadUrl="/api/FileManager/Upload" 
                                 DownloadUrl="/api/FileManager/Download" 
                                 GetImageUrl="/api/FileManager/GetImage"> 
        </FileManagerAjaxSettings> 
    </SfFileManager> 
</div> 
 
@code{ 
    private async Task MenuClick(MenuClickEventArgs<FileManagerDirectoryContent> args) 
    { 
        if (args.Item.Text == "Open" && args.FileDetails[0].IsFile) 
        { 
            await CustomCall(); // perform any custom operation here after restricting default open 
        } 
    } 
    private async Task Open(FileOpenEventArgs<FileManagerDirectoryContent> args) 
    { 
        if (args.FileDetails.IsFile) 
        { 
            await CustomCall(); // you can perform any custom operation requried from your end here 
        } 
    } 
 
    public class CustomData 
    { 
        public string Action { get; set; } 
    } 
 
    private async Task CustomCall() 
    { 
        HttpClient clientInstance = new HttpClient();
// any custom data to be passed to the function can be added here 
        CustomData requestData = new CustomData 
        { 
            Action = "custom" 
        }; 
        string stringPayload = await Task.Run(() => System.Text.Json.JsonSerializer.Serialize(requestData)); 
        using HttpContent httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); 
        HttpResponseMessage httpResponse = await clientInstance.PostAsync(new Uri(https://localhost:44365/api/FileManager/Custom), httpContent); 
    } 
} 
 
In the above code snippet, we have made a call to the custom function in the file provider service whenever the open menu item is clicked, or a file is opened. 
 
For your convenience, we have also attached a sample in the following link to achieve your requirement.  
 
 
Please check the shared details and let us know if you need any further assistance, we will be happy to assist you. 
 
Regards, 
 
Keerthana R. 


Loader.
Up arrow icon