using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace Test{
class Program
{
static void Main(string[] args)
{
using(SPSite siteCollection = new SPSite("http://sharepoint:24433"))
{
using(SPWeb webSite = siteCollection.OpenWeb())
{
// Get the obsolete content type.
SPContentType obsolete = webSite.ContentTypes["Colour Calendar Mapping"];
// 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
{
try
{
// Delete it.
Console.WriteLine("Deleting content type {0}...", obsolete.Name);
webSite.ContentTypes.Delete(obsolete.Id);
}
catch (Exception e)
{
Console.WriteLine("NOT Possible to Delete, Because "+e.Message);
}
}
}
// 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();
}
}
}
Reference: Using the Object Model to Delete a Content Type
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace Test{
class Program
{
static void Main(string[] args)
{
using(SPSite siteCollection = new SPSite("http://sharepoint:24433"))
{
using(SPWeb webSite = siteCollection.OpenWeb())
{
// Get the obsolete content type.
SPContentType obsolete = webSite.ContentTypes["Colour Calendar Mapping"];
// 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
{
try
{
// Delete it.
Console.WriteLine("Deleting content type {0}...", obsolete.Name);
webSite.ContentTypes.Delete(obsolete.Id);
}
catch (Exception e)
{
Console.WriteLine("NOT Possible to Delete, Because "+e.Message);
}
}
}
// 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();
}
}
}
Reference: Using the Object Model to Delete a Content Type
02F45F5E30
ReplyDeleteTakipçi Satın Al
M3u Listesi
Google Yorum Satın Al
Free Fire Elmas Kodu
101 Okey Vip Hediye Kodu
BD3AA67449
ReplyDeleteIn today's digital age, having a strong online presence is essential for any business. Many companies find that optimizing their website can significantly improve customer engagement and sales. By focusing on user experience and content quality, businesses can stand out in a competitive market. For more insights, visit website.