共用方式為


SPContentType.DocumentTemplateUrl property

取得或設定內容類型的文件範本的 URL。

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

Syntax

'宣告
Public ReadOnly Property DocumentTemplateUrl As String
    Get
'用途
Dim instance As SPContentType
Dim value As String

value = instance.DocumentTemplateUrl
public string DocumentTemplateUrl { get; }

Property value

Type: System.String
文件範本的 URL。預設值是String.Empty。

備註

如果沒有文件範本的內容類型,這個屬性的值會是空字串。否則,值可以是伺服器相對 URL 或絕對 URL 的範本,根據文件範本是否存在於目前的網站 (伺服器相對 URL) 或位於另一個網站 (絕對 URL)。

當內容類型套用到程式庫時,會將內容類型的文件範本複製到程式庫的 「 表單 」 資料夾。在此情況下, DocumentTemplateUrl屬性的值永遠是伺服器相對 URL。

Examples

下列範例是一個主控台應用程式,取得網站內容型別的參考和一份已套用至網站中的文件庫的相同內容類型的參考。接著應用程式會列印每個內容類型的**DocumentTemplate()**屬性和DocumentTemplateUrl屬性的值。

請注意,範例程式碼假設存在名為 「 測試提案,」 稱為 [測試文件] 的文件庫的內容型別,會在上傳的內容類型的文件範本。

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();
        }
    }
}

應用程式是列印下列輸出到主控台。

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...

請參閱

參照

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

其他資源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy