Creating albums: native vs fluent API - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Creating albums: native vs fluent API

  • Creating albums: native vs fluent API
  • 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, "-");
        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
  • 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.
  • 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.
  • 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():


    That does the trick!
  • 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.

    Stefani Tacheva
    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