Friday, August 19, 2011

Using the Object Model to Delete a Content Type

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

3 comments:

  1. BD3AA67449
    In 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.

    ReplyDelete

  2. § 27001 beschreibt, wie Unternehmen ihre Informationssicherheit systematisch managen. Der Unterschied zwischen BSI Grundschutz-Check und ISO 27001 zeigt sich in der Praxis an der Herangehensweise. Während der Grundschutz eher standardisiert ist und auf Maßnahmenkatalogen basiert, setzt die ISO auf ein umfassendes Managementsystem mit regelmäßigen Audits. Eine Untersuchung von https://csvisor.de/ legt nahe, dass viele Firmen den Aufwand unterschätzen, um beide Ansätze effektiv umzusetzen. Die ISO fordert seit 2023 eine kontinuierliche Verbesserung des Sicherheitsmanagements, während der BSI Grundschutz vor allem bei kleineren Organisationen beliebt ist. Für Organisationen in kritischen Infrastrukturen gelten spezielle Vorgaben nach § 8 BSI-Gesetz, die eine Kombination beider Standards empfehlen. Das Ziel bleibt stets, das Risiko von Datenverlust oder Angriffen wie Ransomware-Attacken zu minimieren.

    ReplyDelete

Featured Post

How to Create a Self-Signed Certificate and Upload It to Azure App Registration Using PowerShell

How to Create a Self-Signed Certificate and Upload It to Azure App Registration Using PowerShell Securing your Azure app with certificate-b...

Popular posts