Export (0) Print
Expand All

SPContentType.ResourceFolder Property

Windows SharePoint Services 3

Gets the relative folder path for the content type's resource folder.

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

public SPFolder ResourceFolder { get; }

Property Value

Type: Microsoft.SharePoint.SPFolder
An SPFolder object that represents the resource folder.

The resource folder is the storage location for any file, such as a document template, that is used by the content type.

The following example is a console application that displays information about the resource folder for every content type on every list in a Web site. As it iterates through the lists and their content types, the application collects the total size of files in each resource folder and prints an accumulated total to the console at the end of the run.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               long resourceSize = 0;
               foreach (SPList list in web.Lists)
               {
                  foreach (SPContentType ct in list.ContentTypes)
                  {
                    resourceSize += ResourceFolderInfo(list, ct);
                  }
               }
               Console.WriteLine("\nTotal size of files in all resource folders = {0} bytes", resourceSize.ToString());
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }

      private static long ResourceFolderInfo(SPList list, SPContentType ct)
      {
         if (list == null || ct == null)
            throw new ArgumentException();

         SPFolder fldr = ct.ResourceFolder;
         long total = 0;

         Console.WriteLine("\nContent type name: {0}", ct.Name);
         Console.WriteLine("Relative path to resource folder: {0}", fldr.ServerRelativeUrl);
         
         Console.Write("Files in folder:");
         foreach (SPFile file in fldr.Files)
         {
            Console.WriteLine(" {0}", file.Name);
            total += file.Length;
         }

         Console.WriteLine();
         return total;
      }
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft