3

I have a .NET(C#) script which is pulling news articles from an XML file. Everything works fine, but when it comes to publishing them, and appearing on the web page, something's not quite right.

Here's the code so far:

            try {
                    newNode.Save();
                    newNode.Publish(User.GetUser(0));   //0 is default user
                }
                catch (Exception ex) {
                    // error message
                }
                umbraco.library.UpdateDocumentCache(newNode.Id);

As you can see, what I'm trying to publish is newNode. It's first saved and then published through User 0, which has publishing rights, and then the document cache is updated. The problem is that it appears in the back end of Umbraco, but the document link is simply a single hash (#), and it doesn't display on the web page.

Can anyone suggest why this method of publishing wouldn't work?

Edit: Should have mentioned, I'm using Umbraco 4.7.1

edparry
  • 688
  • 1
  • 10
  • 34

1 Answers1

5

If newNode is a child of a node that you are also creating, you'll need to publish and update the document cache for the parent node before publishing (and updating the cache) of its children. At any rate, the parent node needs to be published beforehand. Try republishing the entire site before and, if it still doesn't work, after.

Republishing the entire site:

  1. Right click the Content node.
  2. Select "Republish entire site" from the menu.
  3. Click the "Republish entire site" button.

It should be really quick, as all this is doing is rebuilding the umbraco.config cache file.

Douglas Ludlow
  • 10,754
  • 6
  • 30
  • 54
  • Thanks for the advice, but haven't had any luck with this so far. Could I maybe need to update the cache after trying to publish the newNode's? – edparry Jul 06 '12 at 09:26
  • You should be updating the cache after publishing each node. Make sure all ancestor nodes are properly published beforehand. If worse comes to worst, you can republish (update the cache) for the entire site. I've included instructions on how to do that in the answer. – Douglas Ludlow Jul 06 '12 at 13:10