PreselectedItemUrl incombination with FileExplorer paging

1 Answer 18 Views
FileExplorer
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
Fit2Page asked on 08 May 2025, 11:19 AM | edited on 08 May 2025, 11:20 AM

In my Standalone Image manager I encounter the following: When using StandAlone.AdditionalQueryString = "&PreselectedItemUrl=xxxxxxxx" in combination with File Explorer paging the correct image is not selected. Is there any workaround for this?

 

Thanks,

Marc

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 12 May 2025, 12:14 PM | edited on 12 May 2025, 12:55 PM

Hi Marc,

The PreselectedItemUrl is a QueryString parameter that should be added to the DialogOpener using its set_additionalQueryString() client-side method,e.g.:

<script type="text/javascript">
    var oldAdditionalQueryString = null;  
    function OpenImgManager() {
        var dialogOpener = $find('<%= DialogOpener1.ClientID %>');
        var args = new Telerik.Web.UI.EditorCommandEventArgs("ImageManager", null, document.createElement("img"));
        var txt = $get('<%= TextBox1.ClientID %>');
        
        var itemUrl = "/Images/animal.png"; //path to the image


       
        //add an if check if the txt box is empty set the default itemUrl from above, otherwise set the new textbox value by extracting the src path from the img tag
        if (txt.value != "") {
            var imgTag = txt.value;
            // Extract src value using regex
            var match = imgTag.match(/src=['"]?([^'"]+)['"]?/i);
            if (match && match[1]) {
                var src = match[1];
                // Remove domain if present
                if (src.indexOf(window.location.origin) === 0) {
                    src = src.substring(window.location.origin.length);
                }
                // Ensure it starts with /
                if (src.charAt(0) !== "/") {
                    src = "/" + src;
                }
                itemUrl = src;
            }
        }
        var currentQueryString = dialogOpener.get_additionalQueryString();//get predefined query string
        oldAdditionalQueryString = currentQueryString;
        dialogOpener.set_additionalQueryString(currentQueryString + "&PreselectedItemUrl=" + itemUrl);//add the PreselectedITemUrl parameter
        args.CssClasses = [];
 
        dialogOpener.open('ImageManager', args);
        dialogOpener.set_additionalQueryString(currentQueryString + "&PreselectedItemUrl=" + itemUrl);//add the PreselectedITemUrl parameter
        dialogOpener.set_additionalQueryString(oldAdditionalQueryString);
        oldAdditionalQueryString = null;  
    }
 
    function ImageManagerFunction(sender, args) {
        if (!args) {
            alert('No file was selected!');
            return false;
        }
 
        var path = args.get_value()[0].src;
        var txt = $get('<%= TextBox1.ClientID %>');
        txt.value = "<img src='" + path + "' />";
    }
</script>
 
<asp:TextBox runat="server" ID="TextBox1" Width="400px"></asp:TextBox><br />
<telerik:DialogOpener RenderMode="Lightweight" runat="server" ID="DialogOpener1"></telerik:DialogOpener>
<button onclick="OpenImgManager();return false;">Open ImageManager</button>

I tested this solution and verified that it works as expected in a paging scenario with multiple pages and files.

 

 

Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 14 May 2025, 12:46 PM

Thank you for your reaction, Rumen.

It appears now that the problem we had was due to the fact that the value of the PreselectedItemUrl parameter is case-sensitive. As IIS and Windows folder system are not case-sensitive, shouldn't this be re-factored?

 

Regards,

Marc

Rumen
Telerik team
commented on 14 May 2025, 02:18 PM

Thank you for the follow-up and for identifying the cause of the issue.


You're absolutely right - the case sensitivity of the PreselectedItemUrl parameter can lead to unexpected behavior, especially given that IIS and the Windows file system are not case-sensitive by default. This inconsistency could indeed be confusing.

As a workaround, I'd suggest normalizing the casing of the URLs used in the PreselectedItemUrl parameter to ensure consistency with how the paths are stored or returned in your application.
Tags
FileExplorer
Asked by
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Rumen
Telerik team
Share this question
or