SPSite 构造函数 (String)
Initializes a new instance of the SPSite class based on the specified URL.
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub New ( _
requestUrl As String _
)
用法
Dim requestUrl As String
Dim instance As New SPSite(requestUrl)
public SPSite(
string requestUrl
)
参数
requestUrl
类型:System.StringThe absolute URL for the site collection.
异常
异常 | 条件 |
---|---|
FileNotFoundException | The site collection could not be found. |
备注
The URL that is passed to the SPSite constructor does not need to match a site collection URL exactly. See examples below.
警告
This constructor is allowed in 沙盒解决方案. in that case, the value of the requestUrl parameter must resolve to the parent site collection in which the 沙盒解决方案 is deployed. If the value of the requestUrl parameter resolves to the URL of any other site collection, the constructor throws an exception because a 沙盒解决方案 is not allowed to access any SharePoint objects outside its hosting site collection.
示例
The following code example returns the site collection that is located at https://Server_Name/sites/Site_Name even though the URL that is passed to the constructor does not match the site collection URL.
Using oSiteCollection As New SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx")
...
End Using
using (SPSite oSiteCollection = new SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx"))
{
...
}
The next code example creates an SPSite object using System.Environment.MachineName.
Using oSiteCollection As New SPSite("http://" + System.Environment.MachineName + "/sites/Site_Name")
...
End Using
using (SPSite oSiteCollection = new SPSite("http://" + System.Environment.MachineName + "/sites/Site_Name"))
{
...
}
备注
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.