More in this section

Forums / Developing with Sitefinity / Images & Documents

Images & Documents

4 posts, 0 answered
  1. Razia
    Razia avatar
    9 posts
    Registered:
    10 Jun 2010
    06 Jul 2010
    Link to this post
    HI,

    I want to use the API of sitefinity to load all the images uploaded in the module "Images & Documents".

    I want to list the images like in that module.
    I am actually doing a custom control from which the user can select an image from those librairies.

    Can you please give me the code used by that module to load the images ?

    Thanks
    Razia

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jul 2010
    Link to this post
    Hello Razia,

    Create a custom control that inherits from System.Web.UI.WebControls.Image. The System.Web.UI.WebControls.Image has a property ImageUrl  - Gets or sets the location of an image to display in the System.Web.UI.WebControls.Image. The property  uses System.Web.UI.Design.ImageUrlEditor that will automatically open a  desgner to Images and Documents module from where you can pick up an image. The selector will return dynamic url that you have to resolve. Just pass the returned value to ResolveImageUrl function shown below inside Render method.

    public static string ResolveImageUrl(Control control, string val)
           {
               if (val.StartsWith("~/"))
                   return control.ResolveUrl(val);
     
               int idx = val.IndexOf("]");
     
               if (idx < 0)
               {
                   return val;
               }
     
               string provider = val.Substring(1, idx - 1);
               string strId = val.Substring(idx + 1);
               Guid id = new Guid(strId);
     
               if (ContentManager.Providers.ContainsKey(provider))
               {
                   IContent cnt = ContentManager.Providers[provider].GetContent(id);
                   if (cnt != null && cnt.UrlWithExtension.StartsWith("~/"))
                       return control.ResolveUrl(cnt.UrlWithExtension);
               }
               return String.Concat("Item not found: [", provider, "]", id);
           }

    Another option is creating a custom WebUIType Editor as described in this blog post - Creating a custom WebUITypeEditor

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Razia
    Razia avatar
    9 posts
    Registered:
    10 Jun 2010
    06 Jul 2010
    Link to this post
    HI
    Thanks for your quick reply.

    I did not quite understand how to proceed, can you please provide some more details.

    Thanks
    Razia
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jul 2010
    Link to this post
    Hello Razia,

    I am actually doing a custom control from which the user can select an image from those librairies.

    My reply explains how to create this custom control. Could you tell me what details you need and what is not clear?

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered