+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Creating albums: native vs fluent API

Creating albums: native vs fluent API

5 posts, 1 answered
  1. Lennart
    Lennart avatar
    3 posts
    Registered:
    25 Feb 2012
    31 Jul 2013
    Link to this post
    Hi all,

    I am new to Sitefinity (this is actually my first post) and I have been struggling a bit with creating an album/library via the API. When I try to create an album via the native API as described in the documentation, the album is visible in the back-office but opening the album does not work as expected: the contents of a different album are shown, and the web URL does not contain the album URL name. Below is a sample of the code I'm using (pretty much the same as provided in the docs)

    public Album CreateAlbumIfNotExists(string albumTitle)
    {
        Album album = _libManager.GetAlbums()
            .FirstOrDefault(a => a.Title == albumTitle);
     
        if (album == null)
        {
            album = _libManager.CreateAlbum();
     
            album.Title = albumTitle;
            album.DateCreated = DateTime.UtcNow;
            album.LastModified = DateTime.UtcNow;
            album.UrlName = Regex.Replace(albumTitle.ToLower(), _friendlyUrlRegex, "-");
     
            _libManager.SaveChanges();
        }
     
        return album;
    }

    If I use the fluent API however, everything works as expected. Am I missing something in the above snippet perhaps? Using Sitefinity 6.1
  2. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    31 Jul 2013 in reply to Lennart
    Link to this post
    I would suggest if you can debug the code using Visual Studio to see when it is creating the Album if the UrlName property is being set properly.  Check also you are intending to use Album.Title or Album.Name and the case of albumTitle string matches the Title or Name being returned.
  3. Lennart
    Lennart avatar
    3 posts
    Registered:
    25 Feb 2012
    01 Aug 2013
    Link to this post
    Hi Jonathan,

    Thanks for your reply.
    While debugging I can see the UrlName being set properly, and in a second call the album is retrieved correctly by its title, and the UrlName property is still correct.

    Still not sure what I'm missing. I might have to resort to the fluent API but for this I will need to update all of the interfaces using GUID's instead of Album/Image/IFolder objects.
  4. Lennart
    Lennart avatar
    3 posts
    Registered:
    25 Feb 2012
    02 Aug 2013
    Link to this post
    Telerik support helped me with this issue, and it seems the documentation is missing the following statement, which is to be added right before the call to SaveChanges():

    _libManager.RecompileItemUrls(album);

    That does the trick!
    Answered
  5. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    06 Dec 2016
    02 Aug 2013
    Link to this post
    Hello,

    I am glad to hear that the problem has been resolved using the code we have sent you. Thank you for sharing it with the community.

    Regards,
    Stefani Tacheva
    Telerik
    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
5 posts, 1 answered