Unknown Error..while creating a site


  • Hello All,

    I am trying to create a site using .net managed client object model

    I want to use my custom site template

    following is the code

     string SiteDescription = "About Avatar";
                int SiteLanguage = 1033;
                string SiteTitle = "Avatar";
                string SiteUrl = "Avatar";
                bool SitePermissions = false;
                string mywebTemplate = "{985F9B01-8CC8-448E-9E93-B89A1C332D37}#Avatar";
                ClientContext clientContext = new ClientContext("http://myserver/mysite");
                Web oWebsite = clientContext.Web;
                //Create a new webCreateInformation object to specify the properties of the new site being created.
                WebCreationInformation webCreateInfo = new WebCreationInformation();
                webCreateInfo.Description = SiteDescription;
                webCreateInfo.Language = SiteLanguage;
                webCreateInfo.Title = SiteTitle;
                webCreateInfo.Url = SiteUrl;
                webCreateInfo.UseSamePermissionsAsParentSite = SitePermissions;
                webCreateInfo.WebTemplate = mywebTemplate;
                Web oNewWebsite = oWebsite.Webs.Add(webCreateInfo);
                // Retreiving the server properties to the client context. Here we are retreiving the web server url and the time it was created.
                    Website => Website.ServerRelativeUrl,
                    Website => Website.Created);
                // Executes the query to retreive the required information from the server.

    I am getting unknown error.

    How to trace the correct error?

    Like Cricket

    Saturday, August 24, 2013 2:53 AM

All replies

  • Try to use try{}catch(){} block to catch error.

    Implement logging..

    + stack trace in your logging........
    • Edited by yogesh sainee Saturday, August 24, 2013 8:20 AM update
    • Marked as answer by SharePoint2016 Saturday, August 24, 2013 9:01 AM
    • Unmarked as answer by SharePoint2016 Saturday, August 24, 2013 9:02 AM
    Saturday, August 24, 2013 8:19 AM
  • 1) Try unknown error

    2) to Trace logs ...I have no server access,only remote access

    Like Cricket

    Saturday, August 24, 2013 9:03 AM
  • Hi,

    I can't help you with your error, because it is unknown, but I can share you my code ; which is doing what you want.

    This code works with ajax call, but it's the same way for the creation of the site.

    If you steel meet some issue, please told me !

     protected void Page_Load(object sender, EventArgs e)
                if (httpContext.Request.HttpMethod == "POST" && httpContext.Request.Form["idc"] == "5556")
                    string strURLMonTravail = SPContext.Current.Site.Url + "/BSMonTravail";
                    using (SPSite spsMonTravail = new SPSite(strURLMonTravail))
                        using (SPWeb spwMonTravail = spsMonTravail.OpenWeb())
                            #region 0. Définition des variables
                            string strClient = httpContext.Request.Form["strClient"];
                            string strAffaire = httpContext.Request.Form["strAffaire"];
                            string strIdAffaire = httpContext.Request.Form["strIdAffaire"];
                            string strDateFin = httpContext.Request.Form["strDateFin"];
                            //string GUIDTemplateEspaceAffaire = strGUIDModeleEspaceAffaire();
                            string GUIDTemplateEspaceAffaire = httpContext.Request.Form["strGUID"];
                            SPWeb spwNouveauSite = null;
                            string strResultCreateInfoMonAffaire;
                            string strResultUpdateLinkToEspaceAffaire;
                            #region 1. Tests du GUID
                            //Le GUID n'est pas un message d'erreur
                            if (GUIDTemplateEspaceAffaire.Contains("Erreur")) {
                            //Le GUID est correctement formaté
                            if (!GUIDTemplateEspaceAffaire.Contains("{") && !GUIDTemplateEspaceAffaire.Contains("}"))
                                httpContext.Response.Write("Erreur 3. - Le GUID n'est pas correctement formaté. Vérifiez qu'il contient bien des accolades");
                            #region 2. Création de l'espace Affaire
                            string description = "Client : " + strClient + " - Affaire : " + strAffaire + " - Date de Fin de Projet Prévue : " + strDateFin;
                            uint LCID = spwMonTravail.Language;
                            // On créé un sous-site pour le projet
                                spwMonTravail.AllowUnsafeUpdates = true;
                                spwNouveauSite = spwMonTravail.Webs.Add(strAffaire, strAffaire, description, LCID, GUIDTemplateEspaceAffaire, true, false);
                                //SPNavigationNode siteNode = spwMonTravail.Navigation.GetNodeByUrl(spwNouveauSite.Url);
                                // On ajoute un lien dans la barre de lancement rapide du site parent ==> Commenté car non nécessaire dans la v1.2 <== ABO
                                /*if (siteNode == null)
                                    siteNode = new SPNavigationNode(spwNouveauSite.Title, spwNouveauSite.Url);
                                    siteNode = spwMonTravail.Navigation.AddToQuickLaunch(siteNode, SPQuickLaunchHeading.Sites);
                                spwMonTravail.AllowUnsafeUpdates = false;
                            catch (Exception ex) { httpContext.Response.Write("4. - Une erreur est survenue à la création du sous-site Affaire. Vérifiez que le libellé de l'affaire n'a pas déjà été attribué. Si le problème persiste, contactez votre administrateur. " + ex); httpContext.Response.End(); }
                            #region 4. Finalisation de la méthode
                            httpContext.Response.Write("L'espace affaire a été créé.");

    Sunday, August 25, 2013 9:00 AM
  • No Server access....No Server Object Model code

    Like Cricket

    Sunday, August 25, 2013 5:37 PM
  • I am on SharePoint Server 2010 enterprise edition

    Like Cricket

    Monday, August 26, 2013 6:52 AM
  • Do the user have the permissions to create new web under which this code is running?


    Monday, August 26, 2013 7:29 AM
  • Hi,

    Your code works in my testing with the default site template.

    Would you please first check with default template? If it works, then the issue will be related to your custom template.

    Make sure the template is correct and make create site based on it, and the mywebTemplate parameter value in the code snippet is correct.


    Qiao Wei
    TechNet Community Support

    Monday, August 26, 2013 10:04 AM
  • I think the problem with the features that are activated/deactivated both the ends (Source and Destination)

    I am not sure which features I need to activate/deactivate

    I think Microsoft should provide documentation on all these use cases

    Like Cricket

    Monday, August 26, 2013 11:25 AM