SfFileManager - Copy link of selected item to clipboard

Hi there,

basically we must be able to select existing images on the server directly in the RichText-editor to build up CMS functionality.
Unfortunatelly, there is no SyncFusion Asset manager so far, hope you add one soon...

Right now all we can do is to manually enter a given ImageUrl:


So here is my solution:


As a quick-and-dirty work-around, until you integrate a basic asset manager to your RichText component (that I have to strongly recommend), I need to read out the relative path of an existing image-file on the server to paste it here.

I added a custom property to the context menu of the FileManager to provide the link of the selected item:


This is the filemanger:
<SfFileManager View="ViewType.Details" @ref="Filemanager">
    <FileManagerAjaxSettings Url="/api/FileData/FileOperations"
                                DownloadUrl="/api/FileData/Download"
                                GetImageUrl="/api/FileData/GetImage"
                                UploadUrl="/api/FileData/Upload">
    FileManagerAjaxSettings>
    <FileManagerEvents OnMenuClick="menuClick">FileManagerEvents>
    <FileManagerContextMenuSettings File="@Items" Folder="@Items">FileManagerContextMenuSettings>
SfFileManager>


Please help me to get this part working:
SfFileManager Filemanager;
public string[] Items = new string[] { "Open""|""Delete""Download""Rename""|""Details""Copy link" };
public async Task menuClick(MenuClickEventArgs args)
{
    if (args.Item.Text == "Copy link")
    {
        var selectedFiles = await Filemanager.GetSelectedFiles();
 
        //paste the URL into the Clipboard...
        //your code goes here:
 
    }
}

Cheers,
Volker

3 Replies

SP Sowmiya Padmanaban Syncfusion Team May 21, 2020 02:19 PM UTC

Hi Volker,  
 
Greetings from Syncfusion support. 
 
Query1 – Adding image in RichTextEditor  
 
We have validated your reported query. The Image URL textbox in the Image dialog, can be used only for adding the image from online source. Adding the relative path for images is not possible. Instead ,you can configure the path in the RichTextEditorImageSettings tag using the Path property. 
 
Query 2- Copy link the image link. 
 
We have checked your requirement for fetching the image path using context menu click event. Yes, it is possible to achieve it in the FileManager component. For your reference, we have prepared a sample. 
 
Refer the below code snippet. To achieve this, you need to combine the root path and selected item path. 
 
public async Task click(MenuClickEventArgs args) 
    { 
        if (args.Item.Text == "Copy link") 
        { 
            this.value = true; 
            //Fetching the root path. 
            string Rootpath = JsonConvert.SerializeObject(this.file.AjaxSettings); 
            Dictionary<string, dynamic> Root_path = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(Rootpath); 
            // Get selceted items. 
            var selected_item = await this.file.GetSelectedFiles(); 
            string dataString = JsonConvert.SerializeObject(selected_item[0]); 
            Dictionary<string, dynamic> items_value = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(dataString); 
            // Combine the root path and selected item path. 
            value1 = Root_path["getImageUrl"] + "?path=" + (items_value["filterPath"] +items_value["name"] ).Replace('\\', '/'); 
            this.StateHasChanged(); 
        } 
    } 
 
Refer the below screenshot. 
 
 
 
 
Refer the sample link below. 
 
Please let us know, if you need any further assistance. 
 
 
Regards,  
Sowmiya.P 



VO Volker May 29, 2020 07:36 AM UTC

Hi Somwiy,

thank you ver much!

Adapted your solution so that I'm now able to use my own picture manager within richtext editor
(SfRichTextEditor + SfFileManager)

Cheers,
Volker


SP Sowmiya Padmanaban Syncfusion Team May 29, 2020 02:06 PM UTC

Hi Volker,  
 
We are happy to hear that your problem has been resolved. Please let us know, if you need any help from us. We will happy to assist you. 
 
Regards,  
Sowmiya. P 


Loader.
Up arrow icon