Copied to clipboard

Flag this post as spam?

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


  • Andrei Gorshunov 5 posts 25 karma points
    Apr 17, 2013 @ 21:42
    Andrei Gorshunov
    0

    Programmatic node creation problem

    Hi all!

    I try to create umbraco node programmatic using next code:

    var author = new User("user name");
    Document doc = Document.MakeNew(
        "node name", DocumentType.GetByAlias("ItemAlias"), author, parentNode.Id);
    
    doc.SetProperty("firstName", cartModel.PersonalData.FirstName);
    doc.SetProperty("lastName", cartModel.PersonalData.LastName);
    doc.Save();
    doc.Publish(true);
    library.UpdateDocumentCache(doc.Id);

    Item creates successfully, visible in content tree, publised but when I try to search it by Id or other properties - I can't find it. (republishing and resaving node not working)

    When I restart application - it works, node is findable. But when I change any property value, save and publish item I can't see it in appropriate page.

    So, please help, what is the reason of this problem?

    Thanks.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 17, 2013 @ 22:56
    Jan Skovgaard
    0

    Hi Andrei and welcome to our :)

    Is it the internal search (In Umbraco) for the newly created node that does not display the node before the application has been restarted?

    /Jan

  • Andrei Gorshunov 5 posts 25 karma points
    Apr 17, 2013 @ 23:08
    Andrei Gorshunov
    0

    Hi Jan, thanks)

    This is simple search by nodes:

    HomeNode.GetDescendantNodesByType("ItemAlias").Where(=> {

    var orderIdProp x.GetProperty("orderId");

    var emailProp x.GetProperty("email");

    if(orderIdProp != null && emailProp != null{

    return string.Equals(orderIdProp.Value"orderIdValue"StringComparison.CurrentCultureIgnoreCase)&&
    string.Equals(emailProp.Value"emailValue"StringComparison.CurrentCultureIgnoreCase);
    }

    return false;

    }).FirstOrDefault());

    It finds nodes only after application restart (also if I change property value this change will be visible only after restart).

     

  • Andrei Gorshunov 5 posts 25 karma points
    Apr 20, 2013 @ 10:18
    Andrei Gorshunov
    0

    Does anybody can help me??

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 23, 2013 @ 12:25
    Dave Woestenborghs
    0

    Hi Andrei,

    It seems your cache doesn't get updated.

    Does it work when you change and publish a node in the backend ?

    Can you link your umbracoSettings.config to see what values these settings have.
    -  XmlCacheEnabled
    -  ContinouslyUpdateXmlDiskCache
    - XmlContentCheckForDiskChanges

    Also can you check if you have sufficient security rights on the umbraco.config file in the App_Data folder

    Dave

  • Andrei Gorshunov 5 posts 25 karma points
    Apr 23, 2013 @ 12:40
    Andrei Gorshunov
    0

    Hi Dave,

    Here's configuration:

     

    <!-- Enable / disable xml content cache -->
    <XmlCacheEnabled>True</XmlCacheEnabled>
    
    <!-- Update disk cache every time content has changed -->
    <ContinouslyUpdateXmlDiskCache>True</ContinouslyUpdateXmlDiskCache>
    
    <!-- Update in-memory cache if xml file is changed -->
    <XmlContentCheckForDiskChanges>False</XmlContentCheckForDiskChanges>
    Security rights: Full control.

     

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 23, 2013 @ 12:41
    Dave Woestenborghs
    0

    Does it update the cache when you publish item in the backoffice ?

  • Andrei Gorshunov 5 posts 25 karma points
    Apr 23, 2013 @ 12:49
    Andrei Gorshunov
    0

    In my first post you can see the code I use, the last line is

    library.UpdateDocumentCache(doc.Id);

    So I think it should, but how to check.

    All is working correctly if work with Document directly, not Node.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 23, 2013 @ 13:07
    Dave Woestenborghs
    0

    Does publishing from Umbraco admin work ?

    You should use Node in your templates. The Document API will also list unpublished content and content that is in the recycle bin. Also for performance it's recommended to use Node because it works on the cache. Document API will access the database.

    Dave

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 23, 2013 @ 13:26
    Dave Woestenborghs
    0

    Can you try calling this method after updating document cache ?

    umbraco.library.RefreshContent();

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft