2

We have sharepoint 2010 foundation server for development and enterprise edition in live. We have one .NET web part which create a site based on the logic which works fine in development server(Foundation). Same code we used in live(Enterprise edition) creates the site first time but not the second time.

What is our problem here? I shared the code which create the site

    private void CreateNewSite(SPWeb web, string sSiteName,string sSiteTemplate)
    {
        string sSiteUrl = web.Url + "/" + sSiteName;

        if (!SiteExists(sSiteUrl))
        {
            try
            {
                web.AllowUnsafeUpdates = true;



                string url = sSiteName;
                string title = sSiteName;
                string description = sSiteName + " Site Testing";
                string type = System.Configuration.ConfigurationSettings.AppSettings["SiteTemplateId"];



                // Site creation with unique permissions
                SPWebCollection webs = web.Webs;
                SPWeb newWeb = webs.Add(url, title, description, 1033, type, true, false);


                newWeb.Navigation.UseShared = true;

                //Adds to site navigation
                SPNavigation nav = newWeb.ParentWeb.Navigation;
                SPNavigationNode node = new SPNavigationNode(newWeb.Title, newWeb.ServerRelativeUrl);
                node = nav.AddToQuickLaunch(node, SPQuickLaunchHeading.Sites);

                //Adds to top quick link
                SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;
                node = topnav.AddAsLast(node);

                // Changing the request access email to current user
                newWeb.RequestAccessEmail = newWeb.CurrentUser.Email;

                // Save changes
                newWeb.Update();

                newWeb.Close(); 
                // Disposing new web object
                //newWeb.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
        }
    }
2

There's definitely no differences in this area (what I call the "core SharePoint API") between Foundation and Server.
The problem is clearly elsewhere. Do you get an error, or simply nothing happens? I bet the latter, and consequently the problem would be in SiteExists(sSiteUrl). Are you sure sSiteUrl is a different one the second run? Can't you have a IsPostBack/control initialization problem that leads to reading the same value from teh TextBox?

  • Yes i'm getting an error "Save Conflict. Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes." when adding the site. But the site is created first time. – Ganee Feb 8 '16 at 6:32
  • Do you know where the error happens? On webs.Add? Do you have the call stack? (by the way I lost my bet... :p) – Evariste Feb 8 '16 at 7:47
  • Also, what do you have to do to reset state to "first time", so the Web part works again? IISRESET? And another thing: what Template do you try to instantiate? – Evariste Feb 8 '16 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.