More in this section

Forums / Developing with Sitefinity / How to get the URL and Name of the existing image.

How to get the URL and Name of the existing image.

2 posts, 0 answered
  1. Hari
    Hari avatar
    9 posts
    18 May 2011
    16 Sep 2011
    Link to this post

    I am trying to upload the image dynamically to the sitefinity library. But every time i upload the same image, its getting upload into the library with the modified name, but i don't want to upload the image if it is already there in library.
    Is their any way to check weather the image with the same name is there in Library or not. and if it is present in the library i want to get its URL.

    Please clarify.

    Thanks & Regards,
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    30 Oct 2017
    19 Sep 2011
    Link to this post
    Hi Harish,

    You can easily check for an existing image using our Images API like this:
    var imageToCheck = App.WorkWith()
                                        .Where(i => i.UrlName == "urlname to check"
                                                        && i.Status== Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
    If you want to check whether there is any image in the database with such UrlName, not only a published one, you can remove the Status check in the lambda expression.
    You can then check if the image exists, and if so get its Urls collection, which contains the default URl ont he item,a s well as any additional URLs added to it. To get the default URL, you can do:
    if (imageToCheck != null)
                    var imageUrl = imageToCheck.Urls.Where(u => u.RedirectToDefault == false).FirstOrDefault().Url;

    For more information, you can refer to our Images API samples.
    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered