Copied to clipboard

Flag this post as spam?

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


  • MK 429 posts 906 karma points
    Apr 20, 2012 @ 23:53
    MK
    0

    Moving Document to a new location and getting its new url

    Hi there, 

    Im moving document to a new location using the following code:

       Document doc = new Document(childDocId);
                doc.Move(newParentDocId);
                umbraco.library.RefreshContent();

     

    The doc is indeed moved to the new location but for some reason I'm still getting the old url even if I'm instantiating a new Node using the doc.Id from above.

    Any Idea on how to get the new url?

    cheers

    mkariti

  • Pasang Tamang 258 posts 458 karma points
    Apr 21, 2012 @ 03:23
    Pasang Tamang
    0

    Hello mkariti,

    Try adding below 2lines of code after doc.Move.

    //Mark document for publish
    doc.Publish(sender.User);
    //Publish the document by Updating umbraco.config file
    umbraco.library.UpdateDocumentCache(doc.Id);

    Once the cache is update you should be able to get new location url.

    Thanks

    PTamang

  • MK 429 posts 906 karma points
    Apr 21, 2012 @ 10:00
    MK
    0

    Hi PTamang,

    Work like a charm!

    Does it have to be in a special order?

    I did the following: 

        Document doc = new Document(childDocId);
               doc.Move(newParentDocId);
               umbraco.library.RefreshContent();
               doc.Publish(new User(0));
               umbraco.library.UpdateDocumentCache(doc.Id);
    

    Also, for reference - I used the following to get the new url:

    umbraco.library.NiceUrl(d.Id)

    Many thanks

    mkariti

  • Pasang Tamang 258 posts 458 karma points
    Apr 21, 2012 @ 17:03
    Pasang Tamang
    0

    Hi mkariti,

    The general concept is first publish the document into new path after that update the cache so we can see all the changes and then refresh the content tree.

    Thanks

    PTamang

  • MK 429 posts 906 karma points
    Apr 21, 2012 @ 17:46
    MK
    0

    Great thanks!

Please Sign in or register to post replies

Write your reply to:

Draft