Copied to clipboard

Flag this post as spam?

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


  • [email protected] 16 posts 28 karma points
    Oct 29, 2009 @ 08:13
    ts@firmaidraet.dk
    0

    Create document through api - publish problem

    Hi all

    Hope someone has a good solution for this problem as it is driving me crazy... :-)

    I've created a synchronizer mechanism in my umbraco-solution which is responsible for adding documents to Umbraco from an external source.

    I've created the synchronizer file as CampaignSynchronizer.aspx in the root of my website (and obviously told Umbraco to not treat this as Umbraco content when it is requested!).

    This aspx file is called with an Id for the external information and will lookup this info itself and then adding the content to Umbraco.

    All is fine - new documents are added to Umbraco when the synchronizer runs but when I try to view the ´content I get a completely white page!

    I do this in my synchonizer:

     

     

    d.SaveAndPublish();

     

    umbraco.

    library.UpdateDocumentCache(d.Id);

    umbracoUtilities.Search.

    Indexer.AddPageToIndex(d.Id);

    (where d is a Document type)

    As I stated everything look fine in Umbraco - the document is there - has the icon of published but when I try to view the page - totally white page is shown...

    I found out that a workaround is to hit the "Save and publish" button in Umbraco - then the page views fine....?

    My concern is that maybe Umbraco doesn't see this content as published. In the page view we use "nodes" of this documenttype when showing it. 

    Any help will be greatly appreciated...

    Kind regards, Thomas

  • Richard Soeteman 4036 posts 12864 karma points MVP
    Oct 29, 2009 @ 09:20
    Richard Soeteman
    0

    Hi Thomas,

    Below you find an example to create a document and publish it. In your CampaignSynchronizer.aspx  page you need to add references to the dll's umbraco,cms,businesslogic and Interfaces.

    What's important when you publish is that you first call the publish method on your document and then call the umbraco.library.UpdateDocumentCache method.

     

     

    Document doc = new Document();

    doc.ContentType =

    DocumentType.GetByAlias("the alias of your doctype");

    doc.Text =

    "TestTitle"

     

    //Set properties

    doc.Save();

    doc.Publish(

    new User(0));

    umbraco.

    library.UpdateDocumentCache(doc.Id);

    Hope it helps you,

    Richard

  • [email protected] 16 posts 28 karma points
    Oct 29, 2009 @ 09:37
    ts@firmaidraet.dk
    0

    Hi

    After looking into the code I discovered a bug... (not in Umbraco but my own code...) :-)

    I had to versions of the hitting the create document (one with a new document and one to update existing) and when entering the create I forgot to publish the document...!

    Sometimes you just need to look at the little things... :-)

    This post is no more...

    Kind regards

    Thomas

Please Sign in or register to post replies

Write your reply to:

Draft