This is a migrated thread and some comments may be shown as answers.

ImageManager - Custom Content Provider

10 Answers 275 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 30 May 2013, 06:57 AM
I have successfully created a custom content provider to use a database id instead of a path, i.e. when inserting an image my provider inserts <img src="GetImage.aspx?id=1234" />   Everything works great, except when I click on the image in the content area and then open the ImageManager.  Then I get the error "NonExistingFolder".  As indicated by other threads, this is clearly because I need to convert GetImage.aspx?id=1234, back to a path, which is simple enough.  What is not clear, is where in the content provider to place the conversion code?  

The constructor receives the src value in SelectedItemTag and SelectedUrl, but changing these values in the constructor didn't have any impact.  Where should I be putting the code restore the src value to a valid path?

Thanks,
Dave

10 Answers, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 03 Jun 2013, 03:32 PM
Hello Dave,

Basically, there are two possible options that you have in order to achieve the desired scenario. Both of them requires modifying the FileBrowser.ascx dialog of the RadEditor:
  • In the first approach you will need to attach a handler to the FileExplorer's load event where to reset its initial path to an empty string. This will not make the ImageManager navigate to the selected image, but will prevent the error message to be shown. More information regarding how to execute Server-side code in an Editor's dialog is available here: Displaying single upload control in the FileBrowser Upload manager
    <script runat="server" type="text/C#">
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            string path;
            Telerik.Web.UI.RadFileExplorer radFileExplorer1 = (Telerik.Web.UI.RadFileExplorer)this.FindRadControl(this.Page);
             
            if (radFileExplorer1 != null)
            {
                radFileExplorer1.Load+=new EventHandler(radFileExplorer1_Load);
            }
     
        }
     
        protected void radFileExplorer1_Load(object sender, EventArgs e)
        {
            (sender as Telerik.Web.UI.RadFileExplorer).InitialPath = "";
        }
     
        private Control FindRadControl(Control parent)
        {
            foreach (Control c in parent.Controls)
            {
     
                if (c is Telerik.Web.UI.RadFileExplorer) return c;
                if (c.Controls.Count > 0)
                {
                    Control sub = FindRadControl(c);
                    if (sub != null) return sub;
                }
            }
            return null;
        }
    </script>
  • The second approach is a bit complicated extension of the first one, where you take the current SRC if the selected image so you could use its ID for your custom logic, to pass it as an InitialPath to the FileExplorer control. The path to the selected image is available as a value of the PreselectedItemUrl parameter:
    protected void radFileExplorer1_Load(object sender, EventArgs e)
    {
        //(sender as Telerik.Web.UI.RadFileExplorer).InitialPath = "";
        string path = Request.Params["PreselectedItemUrl"];
        //your custom logic here
    }

I hope this information would be helpful for you.


Regards,
Veselina Raykova
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dave
Top achievements
Rank 1
answered on 04 Jun 2013, 06:29 AM
Hi Veselina,

Awesome!  This worked great.  Thank you very much!  

I used the 2nd approach, as there are times I may not want to revert the ID to a path, but instead allow the alert to inform the user the path for the selected link does not exist within their folder. 

One last question:   Is there any way to modify the message within the popup to say something other than "NonExistingFolder" ?

Thanks!
Dave
0
Vessy
Telerik team
answered on 06 Jun 2013, 04:19 PM
Hi Dave,

I am glad the provided solutions was helpful for you. You can control the text shown into the NonExistingFolder in the localization files of the Editor. The content of the error message could be found inside "RadEditor.Dialogs.resx" under the name "NonExistingFolder". More information regarding the localization and how to modify it is available here:
Using Global Resource Files

Kind regards,
Veselina Raykova
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Dave
Top achievements
Rank 1
answered on 06 Jun 2013, 05:10 PM

Thanks, but here's what is in the .resx file:

 

 

<data name="Common_NonExistingFolder" xml:space="preserve">
  <value>You are trying to navigate to a non-existing folder or you do not have proper permissions to view this folder. Please, contact the administrator.</value>
</data>

When I get the error message, it does not say "You are trying to navigate.....",  it says "NonExistingFolder".   If it were showing the actual message, I wouldn't need to change anything. :)    I've included a screen shot that shows the error alert.

Thanks again!
Dave
0
Vessy
Telerik team
answered on 11 Jun 2013, 03:47 PM
Hi Dave,

This is a really strange behavior - it seems that for some reasons the Editor on your page does not access its localization files. I tried to reproduce this issue with the DB content provider from this code library, but the error message was displayed properly on my test page - screenshot.

For my test I have used the latest official release (2013.1.417). I have attached a sample project to this message, could you try it and tell me whether you can reproduce the same behavior with it? If no - could you modify it up to a point where the problem occurs and send it back?

Looking forward to hearing from you,
Veselina Raykova
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Eric
Top achievements
Rank 1
answered on 28 May 2014, 03:46 PM
We ran into this issue while implementing a custom provider for Amazon S3. Rather than going through the process of implementing an entirely new control and managing events just to clear a string (initial path), we simply went into our ContentProviderBase : FileBrowserContentProvider and added the following to the constructor, essentially resetting the querystring to match that of an initial request with no image selected - 

if (context.Request.QueryString["PreselectedItemUrl"] != null)
{
    var queryString = HttpUtility.ParseQueryString(context.Request.QueryString.ToString());
    queryString.Remove("PreselectedItemUrl");
    string redirect = string.Format("{0}?{1}", context.Request.Url.AbsolutePath,queryString);              
    context.Response.Redirect(redirect, true);
}
0
Eric
Top achievements
Rank 1
answered on 28 May 2014, 03:48 PM
To clarify, this applies to the current thread to some degree, but mainly towards the link below which I'm unable to reply to.

http://www.telerik.org/forums/two-errors-in-the-editor-image-manager-when-working-w-3rd-party-images#ecKOCjo9j0Od6NGkcfzZkQ
0
Vessy
Telerik team
answered on 02 Jun 2014, 12:09 PM
Hi Eric,

Do you experience the same issue while using the implemented by us Amazon S3 FileBrowserContentProvider? Can you compare the files from this article and see what are the differences between it and your own implementation?

If this does not help, could you try to isolate the problem into a sample fully runnable project in the way described in this blog post and send it for a further investigation?

Looking forward to hearing from you,
Vessy
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark Caldwell
Top achievements
Rank 1
answered on 21 Aug 2015, 05:49 PM

To make this solution work, the code must be placed in a custom user control, as outlined in this thread:

http://www.telerik.com/forums/two-errors-in-the-editor-image-manager-when-working-w-3rd-party-images

 

0
Mark Caldwell
Top achievements
Rank 1
answered on 21 Aug 2015, 06:51 PM
Also, I tried Eric's solution(modifying FileBrowserContentProvider), and it also works, and I like his solution the best, as I only have to modify an existing class and do not have to put all this EditorDialogs stuff into my project.
Tags
Editor
Asked by
Dave
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Dave
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Mark Caldwell
Top achievements
Rank 1
Share this question
or