Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

SPSite.OpenWeb - Méthode

Returns the Web site that is associated with the URL that is used in an SPSite constructor.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

public SPWeb OpenWeb()

Valeur renvoyée

Type : Microsoft.SharePoint.SPWeb
An SPWeb object that represents the Web site.

When used in conjunction with an SPSite constructor, the OpenWeb method returns the lowest-level site specified by the URL that is passed as parameter for the constructor. For more information about using the OpenWeb method with an SPSite constructor, see the OpenWeb method overload.

The following code example returns the Web site that is located at http://Server_Name/sites/Site_Name/Subsite_Name.

string strUrl = 
   "http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx";
using (SPSite oSiteCollection = new SPSite(strUrl))
{
    using(SPWeb oWebsite = oSiteCollection.OpenWeb())
    {
        ...
    }
}
RemarqueRemarque

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Afficher: