Compartir a través de


del método PublishingSite.IsPublishingSite

Comprueba el objeto SPSite para determinar si también es un objeto PublishingSite .

Espacio de nombres:  Microsoft.SharePoint.Publishing
Ensamblado:  Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)

Sintaxis

'Declaración
Public Shared Function IsPublishingSite ( _
    site As SPSite _
) As Boolean
'Uso
Dim site As SPSite
Dim returnValue As Boolean

returnValue = PublishingSite.IsPublishingSite(site)
public static bool IsPublishingSite(
    SPSite site
)

Parámetros

Valor devuelto

Tipo: System.Boolean
Se establece en true si se ha activado la función de PublishingResources para el objeto SPSite ; de lo contrario, se establece en false.

Excepciones

Excepción Condición
ArgumentNullException

SPSite no puede ser una referencia null (Nothing en Visual Basic).

Comentarios

Comprueba el SPSite para determinar si se ha activado la función de PublishingResources en el objeto SPSite . Debe llamar a este método antes de que se crea una instancia de un objeto PublishingSite .

Ejemplos

using SPSite = Microsoft.SharePoint.SPSite;
using PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite;
using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PublishingWebCollection = Microsoft.SharePoint.Publishing.PublishingWebCollection;
using SPWebTemplate = Microsoft.SharePoint.SPWebTemplate;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingWebCollectionCodeSamples
    {

  // This method creates a new PublishingWeb below the root Web of a PublishingSite object.
  //
  // Prerequisites:
  // The SPSite passed should be a site that supports publishing.
  //
  // This sample demonstrates use of:
  // PublishingSite.IsPublishingSite( SPSite )
  // PublishingSite constructor
  // PublishingSite.RootWeb
  // PublishingWeb.GetPublishingWebs()
  // PublishingWeb.Web
  // PublishingWebCollection.Add(string, uint, string)
  public static void CreatePublishingWebBelowRoot( SPSite site, SPWebTemplate webTemplate )
  {
// Replace these variable values and input parameters with your own values.
// yourWebURL: name for the PublishingWeb object to create.
string yourWebUrlName = "yourWebUrl";

PublishingWeb newWeb = null;

try
{
    //
    // Validate the input parameters.
    //
    if (null == site)
    {
  throw new System.ArgumentNullException("site");
    }
    if (null == webTemplate)
    {
  throw new System.ArgumentNullException("webTemplate");
    }

    PublishingSite publishingSite = null;
    if (!PublishingSite.IsPublishingSite(site))
    {
  throw new System.ArgumentException(
"The SPSite is expected to be a PublishingSite",
"site");
    }
    publishingSite = new PublishingSite( site );

    SPWeb rootWeb = publishingSite.RootWeb;
    if( !PublishingWeb.IsPublishingWeb( rootWeb ))
    {
  throw new System.ArgumentException(
"The SPSite.RootWeb is expected to be a PublishingWeb",
"site");
    }

    PublishingWeb rootPublishingWeb = PublishingWeb.GetPublishingWeb( rootWeb );
    PublishingWebCollection publishingWebs = rootPublishingWeb.GetPublishingWebs();

    //
    // Create the new PublishingWeb object using the sample values provided.
    //
    newWeb = publishingWebs.Add(
  yourWebUrlName,
  rootWeb.Language,   // Replace with your own language value.
  webTemplate.Name ); // Replace with your Web template name.

    // The new PublishingWeb has the Publishing feature active.
    System.Diagnostics.Debug.Assert(
  null != newWeb.Web.Features[Microsoft.SharePoint.Publishing.FeatureIds.Publishing]);
 
}
finally
{
    //
    // Always close the SPWeb object when done to release memory.
    //
    if( null != newWeb )
    {
  newWeb.Web.Close();
    }
}

  }
    }
}
Imports SPSite = Microsoft.SharePoint.SPSite
Imports PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PublishingWebCollection = Microsoft.SharePoint.Publishing.PublishingWebCollection
Imports SPWebTemplate = Microsoft.SharePoint.SPWebTemplate

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingWebCollectionCodeSamples

  ' This method creates a new PublishingWeb below the root Web of a PublishingSite object.
  '
  ' Prerequisites:
  ' The SPSite passed should be a site that supports publishing.
  '
  ' This sample demonstrates use of:
  ' PublishingSite.IsPublishingSite( SPSite )
  ' PublishingSite constructor
  ' PublishingSite.RootWeb
  ' PublishingWeb.GetPublishingWebs()
  ' PublishingWeb.Web
  ' PublishingWebCollection.Add(string, uint, string)
  Private Sub New()
  End Sub
  Public Shared Sub CreatePublishingWebBelowRoot(ByVal site As SPSite, ByVal webTemplate As SPWebTemplate)
' Replace these variable values and input parameters with your own values.
' yourWebURL: name for the PublishingWeb object to create.
Dim yourWebUrlName As String = "yourWebUrl"

Dim newWeb As PublishingWeb = Nothing

Try
    '
    ' Validate the input parameters.
    '
    If Nothing Is site Then
  Throw New System.ArgumentNullException("site")
    End If
    If Nothing Is webTemplate Then
  Throw New System.ArgumentNullException("webTemplate")
    End If

    Dim publishingSite As PublishingSite = Nothing
    If Not PublishingSite.IsPublishingSite(site) Then
  Throw New System.ArgumentException("The SPSite is expected to be a PublishingSite", "site")
    End If
    publishingSite = New PublishingSite(site)

    Dim rootWeb As SPWeb = publishingSite.RootWeb
    If Not PublishingWeb.IsPublishingWeb(rootWeb) Then
  Throw New System.ArgumentException("The SPSite.RootWeb is expected to be a PublishingWeb", "site")
    End If

    Dim rootPublishingWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(rootWeb)
    Dim publishingWebs As PublishingWebCollection = rootPublishingWeb.GetPublishingWebs()

    '
    ' Create the new PublishingWeb object using the sample values provided.
    '
    newWeb = publishingWebs.Add(yourWebUrlName, rootWeb.Language, webTemplate.Name) ' Replace with your Web template name. -  Replace with your own language value.

    ' The new PublishingWeb has the Publishing feature active.
    System.Diagnostics.Debug.Assert(Nothing IsNot newWeb.Web.Features(Microsoft.SharePoint.Publishing.FeatureIds.Publishing))

Finally
    '
    ' Always close the SPWeb object when done to release memory.
    '
    If Nothing IsNot newWeb Then
  newWeb.Web.Close()
    End If
End Try

  End Sub
    End Class
End Namespace

Vea también

Referencia

clase PublishingSite

Miembros PublishingSite

Espacio de nombres Microsoft.SharePoint.Publishing

PublishingSite

IsPublishingWeb