views:

12

answers:

2
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");



            }
        }
    });



}
+1  A: 

You are probably running the code outside the SharePoint, or before the SPContext is initialized (HTTP handler, for example).

Yossarian
could u advise me what needs to be done!!
Hari Gillala
+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
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
What kind of permissions does you user have?
Jeff Norman
The a look at this too, maybe it helps http://blog.bugrapostaci.com/tag/allowunsafeupdates/
Jeff Norman

related questions