Reputation: 11926
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");
}
}
});
}
Upvotes: 1
Views: 37
Reputation: 1044
Put the real url in your code, you can use it like this:
using(SPSite oSiteCollection = new SPSite("http://Your_Server_Name"))
{
using(SPWeb oWebsite = oSiteCollection.OpenWeb("Your_Website_URL"))
{
using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
{
...
}
}
}
Upvotes: 1
Reputation: 16178
You are probably running the code outside the SharePoint, or before the SPContext is initialized (HTTP handler, for example).
Upvotes: 1