Поделиться через


Свойство SPContentType.ResourceFolder

Получает тип содержимого папки ресурсов.

Пространство имен:  Microsoft.SharePoint
Сборка:  Microsoft.SharePoint (в Microsoft.SharePoint.dll)

Синтаксис

'Декларация
Public ReadOnly Property ResourceFolder As SPFolder
    Get
'Применение
Dim instance As SPContentType
Dim value As SPFolder

value = instance.ResourceFolder
public SPFolder ResourceFolder { get; }

Значение свойства

Тип: Microsoft.SharePoint.SPFolder
Папка ресурсов.

Замечания

Папка ресурсов является место хранения для любого файла, такие как шаблон документа, который используется тип содержимого.

Примеры

Следующий пример является консольным приложением, которое отображает сведения о папке ресурсов для каждого типа контента на всех списков на веб-узле. Как выполняется итерация их типы содержимого и списки, приложение собирает общий размер файлов в каждой папке ресурсов и печатает Накопленный итог в конце выполнения на консоль.

Imports System
Imports Microsoft.SharePoint

Module Test
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()
            Dim resourceSize As Long = 0
            For Each list As SPList In web.Lists
               For Each ct As SPContentType In list.ContentTypes
                  resourceSize += ResourceFolderInfo(list, ct)
               Next ct
            Next list
            Console.WriteLine(vbCrLf + "Total size of files in all resource folders = {0} bytes", resourceSize.ToString())
         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

   Private Function ResourceFolderInfo(ByRef list As SPList, ByRef ct As SPContentType) As Long
      If list Is Nothing OrElse ct Is Nothing Then
         Throw New ArgumentException()
      End If

      Dim fldr As SPFolder = ct.ResourceFolder
      Dim total As Long = 0

      Console.WriteLine(vbCrLf + "Content type name: {0}", ct.Name)
      Console.WriteLine("Relative path to resource folder: {0}", fldr.ServerRelativeUrl)

      Console.Write("Files in folder:")
      For Each file As SPFile In fldr.Files
         Console.WriteLine(" {0}", file.Name)
         total += file.Length
      Next file

      Console.WriteLine()
      Return total
   End Function

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://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;
      }
   }
}

См. также

Справочные материалы

SPContentType класс

Элементы SPContentType

Пространство имен Microsoft.SharePoint

DocumentTemplateUrl

Другие ресурсы

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy