csharp 此控制台应用程序测试是否在SharePoint中使用内容类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 此控制台应用程序测试是否在SharePoint中使用内容类型相关的知识,希望对你有一定的参考价值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ContentTypeTest
{
class Program
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://xxxxx"))
{
foreach (SPWeb web in siteCollection.AllWebs)
{
// Get the obsolete content type.
SPContentType obsolete = web.ContentTypes["Leave Request"];
// We have a content type.
if (obsolete != null)
{
IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);
// It is in use.
if (usages.Count > 0)
{
Console.WriteLine("The content type is in use in the following locations:");
foreach (SPContentTypeUsage usage in usages)
Console.WriteLine(usage.Url);
}
// The content type is not in use.
else
{
// Delete it.
Console.WriteLine("Deleting content type {0}...", obsolete.Name);
//webSite.ContentTypes.Delete(obsolete.Id);
}
}
// No content type found.
else
{
//Console.WriteLine("The content type does not exist in this website.");
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
以上是关于csharp 此控制台应用程序测试是否在SharePoint中使用内容类型的主要内容,如果未能解决你的问题,请参考以下文章