Question

I'm creating about 500 pages in a new Umbraco v6.1.6 website using an import script I've coded. I'm using the ContentService api to create the new pages. They are created and seem to save fine. However if I request the value of a checbox list from one of the new pages, I get an empty string.

I've verified that the property is empty in the umbraco.config file however If I manually save the page from the Umbraco back office. the cache will update with the correct value and I suddenly get the correct value returned.

Is there a way to force a cache update or some other form of fix for this issue?

This is the CreateContent method I'm using:

public static IContent CreateContent(string name, string documentTypeAlias, int parentId, Dictionary properties, bool publish = false, int author = 0)
{
    IContent document = null;

    ContentService contentService = new ContentService();
    document = contentService.CreateContent(
                    name, // the name of the document
                    parentId, // the parent id should be the id of the group node 
                    documentTypeAlias, // the alias of the Document Type
                    author);

    foreach (string property in properties.Keys)
    {
        document.SetValue(property, properties[property]);
    }

    // If publish is true, then save and publish the document
    if (publish)
    {
        contentService.SaveAndPublish(document);
    }
    // Else, just save it
    else
    {
        contentService.Save(document);
    }

    return document;
}

Edit:

After looking into the database, I can see that cmsContentXml has the property but the data within it is the same as umbraco.config. I looked into cmsPropertyData and the data is present. So I guess the question is how do I get the data from cmsPropertyData to cmsContentXml?

My Question is simelar to this one: https://stackoverflow.com/questions/17722347/umbraco-6-1-1-when-i-publish-content-via-the-content-service-tags-type-property however it has no replies.

Was it helpful?

Solution

The data from cmsContentXml gets dumped directly into the umbraco.config file so thankfully these are the same.

To make your code a bit more DRY (you're always saving the document in both the if and the else, try this and update the SaveAndPublish method to Publish (and in v7 you can use PublishWithResult to get a detailed result of the publish action):

contentService.Save(document);

// If publish is true, then save and publish the document
if (publish)
{
    contentService.Publish(document);
}

In v7 you could then have a look at the publishResult. If there's something wrong then this will tell you what it is. Most likely it'll just work fine this way though (which could mean that SaveAndPublish is broken, but let's figure out if publishResult has errors).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top