SPSite Class - MSDN documentation

本文关键字:documentation MSDN Class SPSite | 更新日期: 2023-09-27 18:35:09

我意识到这是一个愚蠢的问题,但无法从我的网络"Server Error: 502 - Web server received an invalid response while acting as a gateway or proxy server."访问MSDN,我不能坐在这里摆弄我的拇指。

我知道除了MSDN之外没有替代品,而且我的本地Visual Studio帮助在这个类上没有任何内容。

请有人复制并粘贴Microsoft.Sharepoint SPSite类的条目,特别是构造函数,但整篇文章会很有用。我收到一个FileNotFoundException,需要知道URL属性应该如何格式化。

万一你们中的任何人碰巧知道。

    public Dictionary<string, SPFolder> GetFolderCollection(string siteURL, string docLibraryName)
    {
        using (SPSite oSite = new SPSite(siteURL + ":23179"))
        {
            SPWeb oWeb = oSite.OpenWeb();
            SPList oList = oWeb.Lists[docLibraryName];
            SPFolderCollection oFolders = oList.RootFolder.SubFolders;
            foreach (SPFolder folder in oFolders)
            {
                foundFolders.Add(folder.Name, folder);
            }
            return foundFolders;
        }
    }

编辑:干杯,谷歌缓存ftw。

为了记录,我指向IIS站点根目录,而不是Sharepoint"站点"。混淆了Sharepoint术语。

SPSite Class - MSDN documentation

表示 Web 应用程序中的网站集合,包括 首要网站及其所有子网站。每个 SPSite 对象或站点 集合,在 SPSiteCollection 对象中表示 由 Web 中所有网站集的集合组成 应用。

继承层次结构

系统对象
Microsoft.SharePoint.SPSite

命名空间:Microsoft.SharePoint

程序集:Microsoft.SharePoint (在 Microsoft.SharePoint.dll)

在沙盒解决方案中可用:是

在 SharePoint Online 中可用

[SubsetCallableTypeAttribute] [ClientCallableTypeAttribute(Name = "site", ServerTypeId = "{E1BB82E8-0D1E-4e52-B90C-684802AB4EF6}")] 公共类 SPSite : 可识别

言论

实例化特定网站集的 SPSite 对象 ASP.NET 页面,或控制台中的特定网站集 应用程序中,使用 SPSite 构造函数,如下所示:C# VB

SPSite oSiteCollection = new SPSite("Absolute_URL");

在 ASP.NET 应用程序中,可以使用 SPContext 类,用于返回表示当前 网站集,如下所示:C#

SPSite oSiteCollection = SPContext.Current.Site;

使用 SPWebApplication 类的 Sites 属性返回 表示网站集合的 SPSiteCollection 对象 SharePoint Web 应用程序中的集合。使用索引器返回 集合中的单个网站集。例如,如果 将网站集的集合分配给名为 oSiteCollections,在 C# 中使用 oSiteCollections[index],或者 oVisual Basic 中的 SiteCollections(index),其中索引为 网站集的显示名称或索引号 收集。

某些对象实现 IDisposable 接口,您必须 避免在不再保留这些对象后将其保留在内存中 需要。如果创建自己的 SPSite 对象,则可以使用 Dispose 关闭对象的方法。您也可以改为实现使用 语句,以便 .NET 框架公共语言运行时 (CLR) 自动释放用于存储站点的内存 集合如下:C# VB

using (SPSite

oSiteCollection = new SPSite("Absolute_URL") { ... }

但是,如果您具有对共享资源的引用,例如 该对象由 Web 部件中的 GetContextSite 方法提供,执行 不要使用任一方法关闭对象。在 共享资源会导致发生访问冲突错误。在 具有对共享资源的引用的方案,而是让 Microsoft SharePoint Foundation 或您的门户应用程序管理 对象。

有关良好编码实践的详细信息,请参阅释放 对象。

重要

如果您安装了 Windows SharePoint Services 的基础结构更新 3.0 (KB951695),如果在模拟挂起时调用 SharePoint 对象模型,自定义解决方案可能会失败。如果您使用视窗 身份验证和您的代码从 互联网信息服务 (IIS) 工作进程,请求必须 模拟调用用户的身份。SharePoint Foundation 将 ASP.NET 配置为自动模拟调用用户,但 如果挂起,代码可能会意外工作或失败 模拟 - 例如,通过调用 的 RevertToSelf 函数 Windows API,或通过调用 System.Security.Principal.WindowsIdentity.Impersonate 方法和 传递 IntPtr.Zero 作为用户令牌参数的值。便 您的代码不会显式恢复为 self,它可能被调用 ASP.NET 恢复为自身之后,例如在实现 虚拟路径提供程序;如果代码未模拟调用 用户,它可能无法正常运行。

线程安全

任何公共静态 (在 Visual Basic 中共享)此类型的成员是线程安全的。任何 不保证实例成员是线程安全的。

构造 函数:

    Name    Description
Public method   SPSite(Guid)    Initializes a new instance of the SPSite class based on the specified ID for a site collection.
Public method   SPSite(String)  Initializes a new instance of the SPSite class based on the specified URL.
Public method   SPSite(Guid, SPUrlZone)     Initializes a new instance of the SPSite class based on the specified site collection GUID and URL zone.
Public method   SPSite(Guid, SPUserToken)   Initializes a new instance of the SPSite class based on the specified site collection GUID and user token.
Public method   SPSite(String, SPUserToken)     Initializes a new instance of the SPSite class based on the specified absolute URL and user token.
Public method   SPSite(Guid, SPUrlZone, SPUserToken)    Initializes a new instance of the SPSite class based on the specified site collection GUID, URL zone, and user token.