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");
}
}
});
}
views:
12answers:
2
+1
A:
You are probably running the code outside the SharePoint, or before the SPContext is initialized (HTTP handler, for example).
Yossarian
2010-10-07 10:53:51
could u advise me what needs to be done!!
Hari Gillala
2010-10-07 11:00:31
+1
A:
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)
{
...
}
}
}
Jeff Norman
2010-10-07 10:57:19
I am trying to run the code without using the runwith deleted option , but it brings up the some security permisiion restrictions. so I have to use run with delegated option
Hari Gillala
2010-10-07 10:59:26
The a look at this too, maybe it helps http://blog.bugrapostaci.com/tag/allowunsafeupdates/
Jeff Norman
2010-10-07 11:12:43