Copied to clipboard

Flag this post as spam?

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


  • zell 37 posts 90 karma points
    Jul 21, 2017 @ 07:21
    zell
    0

    dotnetdatasource accessing umbraco context?

    hi is it possible to use a dotnetdatasource and access the umbraco context?

    i'd like to list all document types in my CMS.

    cheers,

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 21, 2017 @ 07:55
    Dave Woestenborghs
    100

    Hi Zell,

    You should be able to use UmbracoContext.Current in your .NET datasource.

    Dave

  • zell 37 posts 90 karma points
    Jul 24, 2017 @ 02:37
    zell
    1

    thank you, perfect! for purpose of completeness - i did the following:

      public class DocumentTypeDotNetDataSource : IDotNetDataSource
      {
        public IEnumerable<KeyValuePair<string, string>> GetEditorDataItems(int contextId)
        {
          return UmbracoContext.Current.Application.Services.ContentTypeService.GetAllContentTypes()
            .OrderBy(d => d.Name)
            .Select(doctype => new KeyValuePair<string, string>(doctype.Alias, doctype.Name))
            .ToList();
        }
      }
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 24, 2017 @ 06:45
    Dave Woestenborghs
    0

    Hi,

    I'm a bit confused ? In the code you posted you still use the content service ?

    Dave

    PS : Never mind. You need all doctypes..so you actually needed them then ContentTypeService. Maybe add some caching so you don't need to get them every time from the database.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft