Copied to clipboard

Flag this post as spam?

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


  • Faiyaz 19 posts 39 karma points
    Dec 03, 2010 @ 13:05
    Faiyaz
    0

    automatically creating a umbraco document from XHTML

    Hi

    We are getting XHTML of few pages from a webservice of our data providers. We need to create a static website using this XHTML content. We are thinking of using Umbraco to create this website dynamically.

    Is there a way in Umbraco to create a document using this XHTML using API ?

    I already know that I could use API to create documents, but this XHTML is creating uncertainity.

    Any thoughts ?

  • Thomas Stock 40 posts 70 karma points
    Dec 06, 2010 @ 09:54
    Thomas Stock
    0

    Hi.

    You could:

    • Make a Document Type with a property "bodyText"
    • Create a template for that Document Type with MasterPage set to "None" to display that property and nothing else. like this:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <umbraco:Item field="bodyText" runat="server"></umbraco:Item>

    • Create a usercontrol GeneratePagesFromWebservice.ascx that calls your webservice and creates new documents, inserting the xhtml in the "bodyText" property.

    Is this more or less what you're looking for or did I misunderstood your requirements?

  • Faiyaz 19 posts 39 karma points
    Dec 06, 2010 @ 10:59
    Faiyaz
    0

    Hi Thomas

    Many thanks. I think this  ie pretyt much it I suppose. I will try this and will get back to you.

     

    Cheers

    Faiyaz

  • Thomas Stock 40 posts 70 karma points
    Dec 06, 2010 @ 11:24
    Thomas Stock
    0

    For your reference, here's an example of how you would add the documents:

    // Get the Root User (user with Id 0)
    User user = umbraco.BusinessLogic.User.GetUser(0);

    // Get the Document Type with the alias 'importedPage'
    DocumentType dt = DocumentType.GetByAlias("importedPage");

    List<ImportedPage> pages = GetPagesFromWebService();

    foreach(var page in pages)
    {
        // Make a new Document
        Document doc = Document.MakeNew(page.Title, dt, user, ParentPageId);

        // Publish the Document
        doc.getProperty("bodyText").Value = page.Xhtml;

        //Mark document as publishable
        doc.Publish(user);

        // Publish the document
        umbraco.library.UpdateDocumentCache(doc.Id);
    }

     

  • Faiyaz 19 posts 39 karma points
    Dec 06, 2010 @ 12:23
    Faiyaz
    0

    Thanks Thomas

     

    Faiyaz

  • Faiyaz 19 posts 39 karma points
    Dec 06, 2010 @ 23:56
    Faiyaz
    0

    Hi Thomas

     

    Can we programatically create folders as well in umbraco ?

     

    for example

    home/portals/long-term-conditions.aspx

     

    "portals" is the folder.

     

    Thanks

    Faiyaz

  • Daniel Bardi 927 posts 2562 karma points
    Dec 07, 2010 @ 00:03
    Daniel Bardi
    0

    Portals would be a document so it would be created the same way

  • Faiyaz 19 posts 39 karma points
    Dec 07, 2010 @ 00:04
    Faiyaz
    0

    Hi Thomas

     

    Can we programatically create folders as well in umbraco ?

     

    for example

    home/portals/long-term-conditions.aspx

     

    "portals" is the folder.

     

    Thanks

    Faiyaz

  • Faiyaz 19 posts 39 karma points
    Dec 07, 2010 @ 00:05
    Faiyaz
    0

    Thanks Daniel

     

    Faiyaz

  • Thomas Stock 40 posts 70 karma points
    Dec 07, 2010 @ 00:11
    Thomas Stock
    0

    There is no such thing as a "document folder" in Umbraco.

    You can build a hiarchy with child and parent documents, much like how an XML file looks like.

    If you want to group documents under an "empty" document, you could just make another Document Type for that. Call it "Document Container" and don't add any properties to it.

    Also consider what you want to happen when the user goes to home/portals in his browser address bar. You could easily call an XSLT in the Document Container's template that lists all child documents, for example. (See Developer Area > Right-click XSLT files > create a new XSLT file and look at the built-in templates)

  • Daniel Bardi 927 posts 2562 karma points
    Dec 07, 2010 @ 00:13
    Daniel Bardi
    0

    ... and add documents as children of the parent ("folder") document

  • Faiyaz 19 posts 39 karma points
    Dec 07, 2010 @ 00:23
    Faiyaz
    0

    Thanks very much both

     

    Very helpful.

     

    Faiyaz

Please Sign in or register to post replies

Write your reply to:

Draft