Copied to clipboard

Flag this post as spam?

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


  • Kristoffer Eriksen 185 posts 465 karma points
    Sep 27, 2011 @ 10:29
    Kristoffer Eriksen
    0

    Document is null after it's created and published

    Hey Umbraco Coders

    I've got a problem, which probably isn't difficult, but I just can't see to firgure it out.

    I've created a very simple import tool of a CSV fil, which create a new node, for each line.

    If the node already exists i Umbraco ( basic check on nodename ), the node is updated with the data from the line.

    If the node doesnt exist, it should be put i a library called "Usorterede" ( Unsorted ).

    If the library/node "Usorterede" doesnt exists, it should be created first.

    I've got a StreamReader to read the CSV file, an iterate through each line with

    string line;
    while ((line = sr.ReadLine()) != null)
    {
    // DO CODE
    }

    First I find the correct node to put the product in, by a propertyvalue

    Document ItemGroup = (from itm in ProductNode.Children
                          where itm.getProperty("itemGroupID") != null
                          where itm.getProperty("itemGroupID").Value.ToString().Equals(values[6])
                          select itm).FirstOrDefault();

    Then, if itemGroup exists, i check to see if "Usorterede" exists and if not, create it

    if (ItemGroup != null) {
    Document UnsortedItemgroupNode = (from itm in ItemGroup.Children
    where itm.ContentType.Alias.Equals("unsortedProducts")
    select itm).FirstOrDefault();

    if (UnsortedItemgroupNode == null) {
    Document UnsortedItemgroup = Document.MakeNew("Usorterede",DocumentType.GetByAlias("unsortedProducts"),new User(0), ItemGroup.Id);
    UnsortedItemgroup.Save();
    UnsortedItemgroup.Publish(new User(0));
    library.UpdateDocumentCache(UnsortedItemgroup.Id);
    library.RefreshContent();
    UnsortedItemgroupNode = UnsortedItemgroup;
    }
    UnsortedNode = UnsortedItemgroupNode;
    }

    and it works out fine, for the first creation, where no "Usorterede" don't exists.

    Then the product gets created in the correct folder, and the code continues to the next line in the CSV file.

    And this is where I don't get it, or i'm just missing something important.

    The next time I run the

    Document UnsortedItemgroupNode = (from itm in ItemGroup.Children
                                     where itm.ContentType.Alias.Equals("unsortedProducts")
                                      select itm).FirstOrDefault();

    the folder I JUST created, isn't found, and when I look at the children count for the itemGroup, it doesnt change.

    But when the code is done, and all the lines has been taken care of, I've got several folders in Umbraco called "Usorterede", "Usorterede (1)", "Usorterede (2)" etc..

    Where am I missing something ?

    It's like the cache isn't updated or something...I don't get it.

  • Kristoffer Eriksen 185 posts 465 karma points
    Sep 27, 2011 @ 11:52
    Kristoffer Eriksen
    0

    I've changed som code, to see if it was the while-loop, thath did something

    var productList = new List<string>();
    string line;
    while ((line = sr.ReadLine()) != null)
    {
    productList.Add(line);
    }
    foreach (var str in productList)
    {
    //DO CODE
    }

    But that didn't do anything. Same problem.

    The children on ItemGroup, don't get updated, before the entire code has run, and I can see several folders in Umbraco named (1), (2) etc...

  • Kristoffer Eriksen 185 posts 465 karma points
    Sep 27, 2011 @ 12:07
    Kristoffer Eriksen
    0

    Solved. I think. At least it now works as it is supposed to.

    Replaced

    if(ItemGroup!=null){
       
    DocumentUnsortedItemgroupNode=(from itm inItemGroup.Children
                                         
    where itm.ContentType.Alias.Equals("unsortedProducts")
                                         
    select itm).FirstOrDefault();

    with:

    if(ItemGroup!=null){
    Document ItmGroup = new Document(ItemGroup.Id);
       
    DocumentUnsortedItemgroupNode=(from itm inItmGroup.Children
                                         
    where itm.ContentType.Alias.Equals("unsortedProducts")
                                         
    select itm).FirstOrDefault();
Please Sign in or register to post replies

Write your reply to:

Draft