Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sherry Ann Hernandez 320 posts 344 karma points
    Jun 09, 2011 @ 07:54
    Sherry Ann Hernandez
    0

    create media folder using api

    Hi,

    I have this requirement that when I create a room type in the content section, it will automatically add the same folder in the media section. With this, how do I create a media folder using the api?

    Thanks,

    Sherry

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 09, 2011 @ 09:31
    Jeroen Breuer
    0

    Here is a sample:

    Media contentFolder = Media.MakeNew("Content", MediaType.GetByAlias("folder"), User.GetUser(0), parentId);

    Also have a look at this topic: http://our.umbraco.org/forum/developers/api-questions/6090-add-media-items-programmaticaly-

    Jeroen

  • Sherry Ann Hernandez 320 posts 344 karma points
    Jun 09, 2011 @ 10:08
    Sherry Ann Hernandez
    0

    Hi Jeroen,

    Here is my code

    void

     

     

    Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)

    {

     

     

    if (sender.Parent.Text.ToUpper().Equals("FLORA GRAND HOTEL"))

    {

     

     

    int galleryID = createMediaFolder(sender, 4954);

     

     

    Document d = new Document(sender.Id);

    d.getProperty(

     

    "roomGallery").Value = createMediaFolder(sender, galleryID);

    }

    }

    But I'm getting an error on this before_Publish event.

  • Sherry Ann Hernandez 320 posts 344 karma points
    Jun 09, 2011 @ 12:22
    Sherry Ann Hernandez
    0

    Can anybody help because i'm getting an error when setting the folder id in the property. I'm getting an error that object is not set to a reference

    this is my new code

     

     

    void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)

    {

     

     

    Media parentMediaFolder;

     

     

    Media ImageFolder;

     

     

    int imageFolderID = 0;

     

     

    Media rootFolder = new Media(4954);

    parentMediaFolder =

     

    Media.MakeNew(sender.Text, new MediaType(1031), UmbracoEnsuredPage.CurrentUser, rootFolder.Id);

    ImageFolder =

     

    Media.MakeNew("Images", new MediaType(1031), UmbracoEnsuredPage.CurrentUser, parentMediaFolder.Id);

    imageFolderID = ImageFolder.Id;

     

     

    Document d = new Document(sender.Id);

    d.getProperty(

     

    "roomGallery").Value = imageFolderID;

    }

Please Sign in or register to post replies

Write your reply to:

Draft