2010-10-07 39 views
1
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"); 



      } 
     } 
    }); 



} 
+0

給予更多detailes,請更多的代碼或解釋更新您的問題 – 2010-10-07 10:54:12

回答

1

您可能正在運行代碼之外的SharePoint,或SPContext初始化之前(例如HTTP處理程序)。

+0

ü可以告訴我需要做什麼! ! – 2010-10-07 11:00:31

1

把真正的網址在你的代碼,你可以使用它像這樣:

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

我試圖運行的代碼沒有使用runwith刪除選項,但它帶來了一些安全允許的限制。所以我必須使用委託選項 – 2010-10-07 10:59:26

+0

運行您用戶擁有什麼樣的權限? – 2010-10-07 11:05:58

+0

也看看這個,也許它有助於http://blog.bugrapostaci.com/tag/allowunsafeupdates/ – 2010-10-07 11:12:43