SPContentType.DocumentTemplateUrl 属性
获取或设置内容类型的文档模板的 URL。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Property DocumentTemplateUrl As String
Get
用法
Dim instance As SPContentType
Dim value As String
value = instance.DocumentTemplateUrl
public string DocumentTemplateUrl { get; }
属性值
类型:System.String
文档模板的 URL。默认值是String.Empty。
备注
如果没有文档模板存在的内容类型,则此属性的值为空字符串。否则为值可以是相对于服务器的 URL 或模板的绝对 URL,具体取决于文档模板是否存在上当前网站 (相对于服务器的 URL),或存在于另一个网站 (绝对 URL) 上。
当内容类型应用于库中时,内容类型的文档模板复制到库的 Forms 文件夹中。在这种情况下, DocumentTemplateUrl属性的值始终是相对于服务器的 URL。
示例
下面的示例是一个控制台应用程序用于获取对网站内容类型的引用和引用相同的内容类型已应用到网站中的文档库的副本。然后应用程序打印每个内容类型**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...