none
Unknown Error..while creating a site

    Question

  • 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.
    
                clientContext.Load(oNewWebsite,
                    Website => Website.ServerRelativeUrl,
                    Website => Website.Created);
    
                // Executes the query to retreive the required information from the server.
                clientContext.ExecuteQuery();

    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 spguy2012 Saturday, August 24, 2013 9:01 AM
    • Unmarked as answer by spguy2012 Saturday, August 24, 2013 9:02 AM
    Saturday, August 24, 2013 8:19 AM
  • 1) Try Catch....gives unknown error

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


    Like Cricket


    • Edited by spguy2012 Saturday, August 24, 2013 11:15 AM
    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;
                            #endregion
    
                            #region 1. Tests du GUID
                            //Le GUID n'est pas un message d'erreur
                            if (GUIDTemplateEspaceAffaire.Contains("Erreur")) {
                                httpContext.Response.Write(GUIDTemplateEspaceAffaire);
                                httpContext.Response.End();
                                return;
                            }
    
                            //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");
                                httpContext.Response.End();
                                return;
                            }
    
                            #endregion
    
                            #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
                            try
                            {
                                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(); }
                            #endregion
    
                           
                            #region 4. Finalisation de la méthode
                            httpContext.Response.Write("L'espace affaire a été créé.");
                            httpContext.Response.End();
                            #endregion
    
    
                        }
    
                    }
    
                }
            }

    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?

    #RoHsTr

    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.

    Thanks,


    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