Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SPContentType.DocumentTemplateUrl property

Gets or sets the URL to the content type’s document template.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public string DocumentTemplateUrl { get; }

Property value

Type: System.String
The URL for the document template. The default value is String.Empty.

The value of this property is an empty string if no document template exists for the content type. Otherwise, the value can be either a server-relative URL or an absolute URL for the template, depending on whether the document template exists on the current site (server-relative URL) or exists on another site (absolute URL).

When a content type is applied to a library, the content type’s document template is copied to the Forms folder of the library. In this case, the value of the DocumentTemplateUrl property is always a server-relative URL.

The following example is a console application that gets a reference to a site content type and a reference to a copy of the same content type that has been applied to a document library in the site. Then the application prints the value of each content type’s DocumentTemplate() property and DocumentTemplateUrl property.

Note that the example code assumes the existence of a content type named “Test Proposal,” a document library named “Test Documents,” and that a document template has been uploaded for the content type.

using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("http://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();

            string contentTypeName = "Test Proposal";
            string libraryName = "Test Documents";

            // Get a reference to a site content type.
            SPContentType siteContentType = oSPWeb.ContentTypes[contentTypeName];
            Console.WriteLine("Site content type");
            Console.WriteLine("Content type: " + siteContentType.Name);
            Console.WriteLine("Document template: " + siteContentType.DocumentTemplate);
            Console.WriteLine("Document template Url: " + siteContentType.DocumentTemplateUrl);
            Console.WriteLine();

            // Get a reference to the same content type after it is applied to a list.
            SPList list = oSPWeb.Lists[libraryName];
            SPContentType listContentType = list.ContentTypes[contentTypeName];
            Console.WriteLine("List content type");
            Console.WriteLine("Content type: " + listContentType.Name);
            Console.WriteLine("Document template: " + listContentType.DocumentTemplate);
            Console.WriteLine("Document template Url: " + listContentType.DocumentTemplateUrl);

            oSPWeb.Dispose();
            oSPSite.Dispose();

            Console.WriteLine();
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

The application prints the following output to the console.

Site content type
Content type: Test Proposal
Document template: Test Proposal.dotx
Document template Url: /_cts/Test Proposal/Test Proposal.dotx

List content type
Content type: Test Proposal
Document template: Test Proposal.dotx
Document template Url: /Test Documents/Forms/Test Proposal/Test Proposal.dotx

Press ENTER to continue...

Show:
© 2015 Microsoft