Copied to clipboard

Flag this post as spam?

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


  • Ahmed 16 posts 96 karma points
    Aug 12, 2013 @ 09:51
    Ahmed
    0

    setting a default template for a document type in C#

    how can i set a default template for a document type using c# code

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Aug 12, 2013 @ 12:13
    Jeroen Breuer
    0

    If you're using the old API there is a property called DefaultTemplate on a DocumentType where you can set it.

    Jeroen

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Aug 12, 2013 @ 12:31
    Kevin Jump
    102

    new Api - very similar - you just have to find the template based on id or alias

     // connect to the contentTypeService 
    IContentTypeService _contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
    
        // get the docType 
        IContentType docType = _contentTypeService.GetContentType(id);
    
        if (docType != null)
        {
                // get the template you want to set. 
                ITemplate template = ApplicationContext.Current.Services.FileService.GetTemplate("myTemplate");
                if (template != null)
                {
                        // set 
                        docType.SetDefaultTemplate(template);
    
                        // save
                        _contentTypeService.Save(docType); 
                }
        }
    
  • Ahmed 16 posts 96 karma points
    Aug 13, 2013 @ 09:58
    Ahmed
    0

    thanks kevin 

    i tried it and its working fine

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies