using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("http://localhost"))
{
using (SPWeb webSite = siteCollection.OpenWeb())
{
// Get the obsolete content type.
SPContentType obsolete = webSite.ContentTypes["Test"];
// We have a content type.
if (obsolete != null)
{
IList 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 site collection.");
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
上記のコードでコンソールアプリケーションを作成し、そのプロジェクトを実行します。このコードは、コンテンツタイプが関連付けられているライブラリを示します。次に、そのライブラリにアクセスして、添付されているコンテンツタイプを削除します。最後に、サイトの操作 - >サイトの設定 - >サイトのコンテンツの種類からコンテンツの種類を削除するか、上記のコードを使用してコンテンツの種類を削除します。
これは私にとってはうまくいってくれました。おかげさまで
問題が見つかりました。私は「2つの」ごみ箱について読むことを続けました。私はサイトと "サイトコレクション"のごみ箱をチェックし続けました。私は、親サイト "Recycle BIN"の上部にある "リンク"を "Site Collection Recycle Bin"と表示していませんでした。そのオプションをクリックして(そして「エンドユーザーのごみ箱から削除する」を選択した後)、コンテンツタイプを削除することができました。 – Shayne