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

Posted by Community Admin on 04-Aug-2018 07:57

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

All Replies

Posted by Community Admin on 16-Sep-2011 00:00

Hi,

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,
Harish

Posted by Community Admin on 19-Sep-2011 00:00

Hi Harish,

You can easily check for an existing image using our Images API like this:

var imageToCheck = App.WorkWith()
                                    .Images()
                                    .Where(i => i.UrlName == "urlname to check"
                                                    && i.Status== Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                                    .Get()
                                    .FirstOrDefault();
           
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

This thread is closed