Try Now
More in this section

Forums / Developing with Sitefinity / Uploading Images to Folder Inside

Uploading Images to Folder Inside

2 posts, 0 answered
  1. Dan
    Dan avatar
    3 posts
    27 Aug 2013
    23 May 2014
    Link to this post

    Hello, I am having trouble finding documentation that explains how to upload an image to an IFolder.  I have an album.  Inside this album, there is a IFolder, and inside this IFolder, there is another IFolder.

    So, Album -> IFolder -> IFolder -> IMAGE_SAVE_HERE.

    When saving an Image Object using the LibraryManager.Upload(Image, MemoryStream, FileExt) command, the Image object being saved must contain a valid Parent.  

    Image.Parent is a Library.  Album extends Library, but IFolder does not.  So, I am unable to assign the nested IFolder I want to the Image.Parent property.

    How do I go about uploading an Image to an IFolder, inside another IFolder, inside an Album?

    Code Example of what I'm doing now - http://pastie.org/9202845


    Thanks in advance for any help!

    PS - When posted, I noticed that I never finished the Topic Title.  So I'm now in Edit mode of the post, but unable to edit the Topic's Title.  This should be a feature added to this forum.

  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    26 Mar 2015
    28 May 2014
    Link to this post
    Hello Daniel,

    The easiest way to achieve this is to assign the image to an album and then relocate it to the Folder. Here is an example:
    var album = librariesManager.GetAlbums().Where(i => i.Title == "TestParent").FirstOrDefault();
    var childFolder = librariesManager.GetChildFolders(album).Where( c => c.Title == "ChildTest").FirstOrDefault();
    image.Parent = album;
    librariesManager.ChangeItemFolder(image, childFolder);

    Documentation on managing folders can be found here.

    Ivan D. Dimitrov
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered