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 @ 14:37
    Sherry Ann Hernandez
    0

    getting an error when creating a media folder on Document_AfterNew Event

    Hi,

    My code for creating a new media folder is not working when I move it on the document_afternew event. It is working if I use the document_beforepublish event but my problem with this is the media folder is created everytime the document is published.

    Here is my code.

    void

     

     

    Document_AfterNew(object sender, umbraco.cms.businesslogic.NewEventArgs e)

    {

     

     

     

    Media parentMediaFolder;

     

     

    Media ImageFolder;

     

     

    int imageFolderID = 0;

     

     

    int rootFolderID = 4954;//getRootFolderID(((CMSNode)sender).Parent.Parent.Text, doc.Text);

     

     

    Media rootFolder = new Media(rootFolderID);

    parentMediaFolder =

     

    Media.MakeNew("test", 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;

     

    }

     

    Can anybody help me how to solve this?

  • Samuel Hamer 44 posts 66 karma points
    Jun 09, 2011 @ 15:33
    Samuel Hamer
    0

    Hi Sherry, I believe the AfterNew event handler fires before the document has actually been created, as you might have noticed sender is still an object at this point and not a document.  Oddly I think Document.New should work... failing that you could make a property like "newDoc" and move it if the property is set 0 and then set the property to 1 after the move..  It wouldnt work if you were copying the document though...

    Just a few thoughts

Please Sign in or register to post replies

Write your reply to:

Draft