sharepoint对象建模

时间:2010-10-07 10:51:17

标签: sharepoint-2007

protected void btnCreateList_Click(object sender, EventArgs e)
{
    SPWeb currentWeb = SPContext.Current.Web;

    Guid webId = currentWeb.ID;

    Guid siteId = currentWeb.Site.ID;
    Response.Write(siteId);

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(siteId))
        {
            using (SPWeb web = site.OpenWeb(webId))
            {
                site.AllowUnsafeUpdates = true;
                Response.Write("configured successfully");



            }
        }
    });



}

2 个答案:

答案 0 :(得分:1)

您可能正在SharePoint外部运行代码,或者在初始化SPContext之前运行代码(例如,HTTP处理程序)。

答案 1 :(得分:1)

将真实的网址放入您的代码中,您可以像这样使用它:

using(SPSite oSiteCollection = new SPSite("http://Your_Server_Name"))
{
    using(SPWeb oWebsite = oSiteCollection.OpenWeb("Your_Website_URL"))
    {
        using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
        {
           ...
        }
    }
}