Freigeben über


SPContentTypeUsage.Url-Eigenschaft

Dient zum Abrufen der URL (Uniform Resource Locator) für den Inhaltstyp.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public ReadOnly Property Url As String
    Get
'Usage
Dim instance As SPContentTypeUsage
Dim value As String

value = instance.Url
public string Url { get; }

Eigenschaftswert

Typ: System.String
Eine serverrelative URL.

Hinweise

Für Websiteinhaltstypen gibt die Eigenschaft eine serverrelative URL für die Website. Listeninhaltstypen gibt die Eigenschaft Url eine serverrelative URL für den Stammordner der Liste zurück.

Beispiele

Das folgende Beispiel zeigt eine Konsolenanwendung, die die Verwendung-Auflistung für die integrierten Inhaltstypen Itemabruft. Die Anwendung verwendet die Url -Eigenschaft der einzelnen SPContentTypeUsage -Objekte in der Auflistung den Namen dieser Instanz des übergeordneten Inhaltstyps ermitteln. Klicken Sie dann druckt die Anwendung den Namen der Instanz des Bereichs (Website oder Liste der Instanz) und den Wert der Url -Eigenschaft in der Konsole angezeigt.

Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("https://localhost")
         Using webSite As SPWeb = siteCollection.RootWeb

            ' Get the content type.
            Dim contentType As SPContentType = _
               webSite.AvailableContentTypes(SPBuiltInContentTypeId.Item)

            ' Get the usage collection.
            Dim usages As IList(Of SPContentTypeUsage) = _
                                SPContentTypeUsage.GetUsages(contentType)

            For Each usage As SPContentTypeUsage In usages

               ' Get the name of this instance.
               Dim ctName As String = String.Empty

               If usage.IsUrlToList Then ' List content type
                  For Each web As SPWeb In siteCollection.AllWebs

                     For Each list As SPList In web.Lists
                        If list.RootFolder.ServerRelativeUrl = usage.Url Then
                           ctName = list.ContentTypes(usage.Id).Name
                           Exit For
                        End If
                     Next list

                     web.Dispose() ' Clean up

                     If ctName <> String.Empty Then
                        Exit For
                     End If

                  Next web

               Else ' Site content type.
                  Dim web As SPWeb = siteCollection.OpenWeb(usage.Url)
                  ctName = web.AvailableContentTypes(usage.Id).Name
                  web.Dispose()
               End If

               Console.WriteLine(vbCrLf + "Content type name: {0}", ctName)
               Console.WriteLine("This is a {0} content type", _
                                 IIf(usage.IsUrlToList, "list", "site"))
               Console.WriteLine("URL: {0}", usage.Url)

            Next usage

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

End Module
using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb rootWeb = siteCollection.RootWeb)
            {
               // Get the content type.
               SPContentType contentType =
                  rootWeb.AvailableContentTypes[SPBuiltInContentTypeId.Item];

               //Get the usage collection.
               IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(contentType);

               foreach (SPContentTypeUsage usage in usages)
               {
                  // Get the name of the content type.
                  string ctName = String.Empty;

                  if (usage.IsUrlToList) // List content type
                  {
                     foreach (SPWeb web in siteCollection.AllWebs)
                     {
                        foreach (SPList list in web.Lists)
                        {
                           if (list.RootFolder.ServerRelativeUrl == usage.Url)
                           {
                              ctName = list.ContentTypes[usage.Id].Name;
                              break;
                           }
                        }

                        web.Dispose(); // Clean up

                        if (ctName != String.Empty)
                           break;
                     }
                  }
                  else // Site content type.
                  {
                     SPWeb web = siteCollection.OpenWeb(usage.Url);
                     ctName = web.AvailableContentTypes[usage.Id].Name;
                     web.Dispose();
                  }

                  Console.WriteLine("\nContent type name: {0}", ctName);
                  Console.WriteLine("This is a {0} content type.", 
                                    usage.IsUrlToList ? "list" : "site");
                  Console.WriteLine("URL: {0}", usage.Url);
               }
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

Wenn die Anwendung für eine Websitesammlung mit einer Stammwebsite und einer untergeordneten Website ausgeführt wird, wird die (partial) folgende Ausgabe in der Konsole ausgegeben.

Content type name: Task
This is a site content type.
URL: /

Content type name: Feature Points of Contact
This is a site content type.
URL: /Subsite

Content type name: Task
This is a list content type.
URL: /Lists/Tasks

Content type name: Feature Points of Contact
This is a list content type.
URL: /Subsite/Lists/Subsite List

Siehe auch

Referenz

SPContentTypeUsage Klasse

SPContentTypeUsage-Member

Microsoft.SharePoint-Namespace

Weitere Ressourcen

Introduction to Content Types

Site and List Content Types