ImageManager - Custom Content Provider

11 posts, 1 answers
  1. Dave
    Dave avatar
    21 posts
    Member since:
    Jul 2012

    Posted 30 May 2013 Link to this post

    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
  2. Answer
    Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 03 Jun 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave
    Dave avatar
    21 posts
    Member since:
    Jul 2012

    Posted 04 Jun 2013 Link to this post

    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
  5. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 06 Jun 2013 Link to this post

    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.
  6. Dave
    Dave avatar
    21 posts
    Member since:
    Jul 2012

    Posted 06 Jun 2013 Link to this post

    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
  7. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 11 Jun 2013 Link to this post

    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.
  8. Eric
    Eric avatar
    3 posts
    Member since:
    Aug 2013

    Posted 28 May 2014 in reply to Vessy Link to this post

    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);
    }
  9. Eric
    Eric avatar
    3 posts
    Member since:
    Aug 2013

    Posted 28 May 2014 in reply to Eric Link to this post

    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
  10. Vessy
    Admin
    Vessy avatar
    1380 posts

    Posted 02 Jun 2014 Link to this post

    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.

     
  11. Mark Caldwell
    Mark Caldwell avatar
    3 posts
    Member since:
    Sep 2009

    Posted 21 Aug 2015 in reply to Vessy Link to this post

    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

     

  12. Mark Caldwell
    Mark Caldwell avatar
    3 posts
    Member since:
    Sep 2009

    Posted 21 Aug 2015 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017