Copied to clipboard

Flag this post as spam?

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


  • Anders Brännmark 226 posts 277 karma points
    Jun 27, 2010 @ 14:07
    Anders Brännmark
    0

    Get all documents by document type?

    Need to get all documents, unpublished and published content for a certain document type. Thought of using this code do so:

     

    private List<Document> GetAllEventDateDocuments()
    {
    DocumentType dt = DocumentType.GetByAlias("EventDate");
    umbraco.cms.businesslogic.Content[] contentNodes = Document.getContentOfContentType(dt);
    List<Document> eventDatesList = new List<Document>();
    foreach (umbraco.cms.businesslogic.Content contentNode in contentNodes)
    {
    Document eventDocument = new Document(contentNode.Id);
    eventDatesList.Add(eventDocument);
    }
    return eventDatesList;
    }

    Anyone have a better way of doing this? Is there any problem using the getContentOfContentType method of a document? And why wouldnt this method return an array of documents instead of an array of umbraco.cms.busniesslogic.Content?

     

  • Tom Maton 387 posts 660 karma points
    Jun 28, 2010 @ 13:57
    Tom Maton
    0

    Does it have to be in a .NET User Control, cant you just use XSLT?

    Something like

    <xsl:for-each select="$currentPage//node [@nodeTypeAlias = 'EventDate']">
    <xsl:value-of select="@nodeName" />
    <\xsl:for-each >

    Tom

     

  • Anders Brännmark 226 posts 277 karma points
    Jun 28, 2010 @ 14:01
    Anders Brännmark
    0

    This is a control in the backend to list documents, and filter them by diffrent criterias. Also it needs to be unpublished documents also, which means, xml, nodefactory and so on is out of the question. Wondering what methods is the best to grab all documents of a certain type. Either using this method and the converting the result to a list och documents or traversing all documents looking for the correct type....

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jun 28, 2010 @ 14:34
    Lee Kelleher
    0

    Hi Anders, I'd say you are taking the best approach to this already.

    If you are using v4.5, then there's a new API call in the Document class/object called: "GetDocumentsOfDocumentType()", try that one instead.

    Cheers, Lee.

  • Anders Brännmark 226 posts 277 karma points
    Jun 28, 2010 @ 14:39
    Anders Brännmark
    0

    Nope, this is an Umbraco 4.0.4.2 so I dont have access to any better methods :-(. Also I have to wait to get a 3.5 compile of the 4.5 before I can upgrade :-(

    Thanks for your response. Will continue on my project on the path I have set then and not worry about this anymore :-)

    /Anders

  • Anders Brännmark 226 posts 277 karma points
    Jun 28, 2010 @ 22:12
    Anders Brännmark
    0

    To follow up on this subject. Is there any better way to check if the "document" is in the trashbin other than checking if the path contains -20?

    Seam that when using the "content" as the base for getting a list of documents one also gets the items in the trashbin.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jun 28, 2010 @ 22:17
    Lee Kelleher
    0

    As far as I'm aware, (also from looking at the core code via Reflector), checking for "-20" in the path is the best way.  In fact that's the way Document.delete() checks it...

    if (!base.Path.Contains(",-20,"))
    {
        ...
    }
    
    Cheers, Lee.
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jun 28, 2010 @ 23:15
    Lee Kelleher
    0

    ... forgot to mention, in v4.5 (which I know you aren't using yet), there is a property called IsTrashed in the CMSNode class/object (which Content inherits from - thus available in Document too).

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jun 29, 2010 @ 05:23
    Aaron Powell
    0

    There is a 3.5 release of Umbraco 4.5, it's just that codeplex doesn't have the appropriate web.config on it yet. See this post: http://our.umbraco.org/forum/core/41-feedback/10084-35-for-45

    But I can tell you now that as your site grows what you're wanting to do will get slower and slower, and this is an unfortunate hold-over from the current data layer design.

  • Anders Brännmark 226 posts 277 karma points
    Jun 29, 2010 @ 08:01
    Anders Brännmark
    0

    Ok. Will have to check up on how to upgrade to 4.5, have lots of xslts so if that will be a hassle to upgrade I have no choise at the moment.

    /Anders

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jun 29, 2010 @ 08:07
    Aaron Powell
    0

    You can set a flag in the umbracoSettings.config which will leave the schema of the XML unchanged.

  • Anders Brännmark 226 posts 277 karma points
    Jun 29, 2010 @ 08:08
    Anders Brännmark
    0

    Yeah I read that somewhere. But will one get the improved speed and such then?

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jun 29, 2010 @ 08:09
    Aaron Powell
    0

    Not improved XPath speed, but the database improvements are agnostic of the XML schema

  • Anders Brännmark 226 posts 277 karma points
    Jun 29, 2010 @ 08:10
    Anders Brännmark
    0

    Ok, maybe I try an upgrade later today then.

    Thanks for the help!

Please Sign in or register to post replies

Write your reply to:

Draft