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

Forums / Sitefinity SDK / Dynamically Create Image Album

Dynamically Create Image Album

2 posts, 0 answered
  1. Scott
    Scott avatar
    7 posts
    Registered:
    02 Jan 2011
    29 Mar 2011
    Link to this post
    I've been trying to dynamically create a image album and I've used the following sample code from the API documentaiton.  The problem is that this code returns an empty GUID and the Album doesn't appear in SiteFinity.  Is this a bug or am I missing something obvious?

    (I'm using SiteFinity 4.0 SP1)

    public static Guid CreateAlbum(string title, string urlName, string description)
    {
        Guid newAlbumId = Guid.Empty;
        App.WorkWith().Album()
            .CreateNew()
            .Do(a =>
                {
                    a.Title = title;
                    a.Description = description;
                    a.UrlName = urlName;
                    newAlbumId = a.Id;
                })
            .SaveChanges();
        return newAlbumId;
    }

    Thanks for your assistance.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Apr 2011
    Link to this post
    Hi Scott,

    Try using this code

    private Album CreateAlbum(urlName)
     {
         var manager = LibrariesManager.GetManager();   
         var album = manager.GetAlbums().ToList().Where(a => a.UrlName == "somename").FirstOrDefault();
         if (album == null)
         {
             App.WorkWith().Album().CreateNew().Do(
                 a =>
                 {
                     a.Title = "Album for blog " + blog.Title;
                     a.Description = "my description";
                    var id = a.Id;
                 }
             ).Get(out album).SaveChanges();
         }
         return album;
     }

    I am not able to replicate the issue you reported. The Id is returned by the Content object

    Regards,
    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
2 posts, 0 answered