Copied to clipboard

Flag this post as spam?

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


  • Christian Liebe-Harkort 56 posts 104 karma points
    Mar 04, 2011 @ 16:22
    Christian Liebe-Harkort
    0

    Enumerate over a collection of documents that are of a particular document type

    I am trying to build a .NET usercontrol that populates a dropdown with all nodes of a certain document type. I found this code snippet at the  "API Cheatsheet" at
    http://our.umbraco.org/wiki/reference/api-cheatsheet/enumerating-documents

    //get the document by its ID
    Document doc = new Document(1029);
    //Root documents
    Document.GetRootDocuments();
    //Get Nodes of a specific type
    DocumentType dt = DocumentType.GetByAlias("Textpage");
    Content[] docs = Document.getContentOfContentType(dt);
    //Get documents which has publishing date set
    //and is either waiting to be published or is expired
    Document.GetDocumentsForRelease();
    Document.GetDocumentsForExpiration();

     

    but Visual Studio complains this line

     

    Content[] docs = Document.getContentOfContentType(dt);


    with this error:

    Error    1    An implicit conversion of the type "umbraco.cms.businesslogic.Content[]" in "System.Web.UI.WebControls.Content[]" is not possible.     (translated from german)

    I have added references to  the cms.dll, businesslogic.dll and umbraco.dll in my project.

    I am using Visual Studio 2010 and umbraco v 4.6.1 (Assembly version: 1.0.4029.25836).

    What am I missing here?

    Christian

  • Patrick McAndrew 48 posts 163 karma points
    Mar 04, 2011 @ 18:19
    Patrick McAndrew
    0

    Christian,

    You're having a namespace clash.  You can either remove the line

    using System.Web.UI.Webcontrols;

    Or try the following line:

    umbraco.cms.businesslogic.Content[] docs = Document.getContentOfContentType(dt);

    You may also want to look into the uComponent project and use uQuery, although you will be restricted to nodes rather than documents (but you should probably be using nodes anyway).

  • Christian Liebe-Harkort 56 posts 104 karma points
    Mar 04, 2011 @ 18:45
    Christian Liebe-Harkort
    0

    HI Patrick,

    thanks a lot. removing using System.Web.UI.Webcontrols; did not work (type or namespace Content[] can not be found) but your second suggestion works fine.

     

Please Sign in or register to post replies

Write your reply to:

Draft