Export (0) Print
Expand All

SPContentType.ParentWeb Property

Windows SharePoint Services 3

Gets the parent Web site for the content type.

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

public SPWeb ParentWeb { get; }

Property Value

Type: Microsoft.SharePoint.SPWeb
An SPWeb object representing the parent Web site.

The value of the ParentWeb property is an SPWeb object that represents the Web site where the SPContentType object exists. The value is the same for all SPContentType objects that exist anywhere within the Web site, no matter whether they are scoped at the site or list level.

The following example is a console application that enumerates all lists in a site, printing the name of each list to the console. In addition, the example code enumerates each list’s content types, printing the name of each content type to the console as well as a server-relative URL for the content type’s parent Web.

using System;
using Microsoft.SharePoint;

namespace MyTest
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("http://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();
            SPListCollection oListCollection = oSPWeb.Lists;

            foreach (SPList oList in oListCollection)
            {
                Console.WriteLine("List title: " + oList.Title);
                Console.WriteLine();
                foreach (SPContentType oContentType in oList.ContentTypes)
                {
                    Console.WriteLine("   Content type name: " + oContentType.Name);
                    SPWeb oParent = oContentType.ParentWeb;
                    Console.WriteLine("   Content type's parent Web: " + oParent.ServerRelativeUrl);
                    Console.WriteLine();
                    oParent.Dispose();
                }
                Console.WriteLine();
            }

            oSPWeb.Dispose();
            oSPSite.Dispose();

            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

Some of the output printed to the console might look like this:


List title: Announcements

   Content type name: Announcement
   Content type's parent Web: /

   Content type name: Folder
   Content type's parent Web: /


List title: Calendar

   Content type name: Event
   Content type's parent Web: /


List title: Links

   Content type name: Link
   Content type's parent Web: /

   Content type name: Folder
   Content type's parent Web: /

Community Additions

ADD
Show:
© 2014 Microsoft