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 4908 posts 12265 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 2342 posts 14889 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

Please Sign in or register to post replies

Write your reply to:

Draft