Partilhar via


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableAttribute> _
Public ReadOnly Property DocumentTemplateUrl As String
    Get
'Usage
Dim instance As SPContentType
Dim value As String

value = instance.DocumentTemplateUrl
[ClientCallableAttribute]
public string DocumentTemplateUrl { get; }

Property Value

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

Remarks

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.

Examples

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.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Console.WriteLine()

        Dim oSPSite As SPSite = New SPSite("https://localhost")
        Dim oSPWeb As SPWeb = oSPSite.OpenWeb()

        Dim contentTypeName As String = "Test Proposal"
        Dim libraryName As String = "Test Documents"

        ' Get a reference to a site content type.
        Dim siteContentType As SPContentType = 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.
        Dim list As SPList = oSPWeb.Lists(libraryName)
        Dim listContentType As SPContentType = 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()
    End Sub

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("https://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...

See Also

Reference

SPContentType Class

SPContentType Members

Microsoft.SharePoint Namespace

Other Resources

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy