Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using SharePoint 2007 and was not able to create site collection and add sites pro grammatically using c# code.

Some times it creates the site collection and some times it doesn't.

works fine for local server...but for LIVE SERVER site collection not created

Can any one describe me the possible causes for this.

share|improve this question
1  
Paste the code the creates the site collection? –  Falak Mahmood Dec 3 '13 at 10:34
1  
Please also look in the ULS logs for any clues. –  James Love Dec 3 '13 at 10:41
    
Hi Falak, I have pasted the code below.... –  monishmanostephen Jan 23 '14 at 5:48

1 Answer 1

        SPWebApplication spwebApplication = null ;

        SPWeb web = null;
        SPSecurity.RunWithElevatedPrivileges(delegate
        {
            string newSiteUrl = string.Empty;
        try
        {
            using (SPSite spSite = new SPSite(GetSharepointURL()))
            {
                spwebApplication = spSite.WebApplication;
                if (spwebApplication != null)
                {
                    //FormDigestSettings to disable security validation settings for this code only.
                    spwebApplication.FormDigestSettings.Enabled = false;
                    var siteCollections = spwebApplication.Sites;
                    if (siteCollections != null)
                        using (SPSite newSite = siteCollections.Add(string.Format("Sites/{0}", journalId), shortname, journalname, 1033, "STS#1"
                         , Frontiers.Configuration.ConfigurationManager.AppSettings["SiteCollectionOwner"], Frontiers.Configuration.ConfigurationManager.AppSettings["SiteCollectionOwnerName"], string.Empty))
                        {
                            newSiteUrl = newSite.Url;
                            if (newSite.AllWebs.Count > 0)
                            {
                                 web = newSite.AllWebs[0];
                                if (web != null)
                                {
                                    web.AllowUnsafeUpdates = true;

                                    Guid id = web.Lists.Add("Articles Library", "Articles Library", SPListTemplateType.DocumentLibrary);
                                    // web.Lists.U
                                    if (id != null)
                                    {
                                        web.Update();
                                        SPList list = web.Lists[id];
                                        list.EnableVersioning = true;
                                        list.OnQuickLaunch = true;
                                        list.Fields.Add("DocumentType", SPFieldType.Text, false);
                                        SetFieldProperties(list.Fields["DocumentType"]);
                                        list.Fields.Add("FileFormat", SPFieldType.Text, false);
                                        SetFieldProperties(list.Fields["FileFormat"]);
                                        list.Fields.Add("DocumentId", SPFieldType.Text, false);
                                        SetFieldProperties(list.Fields["DocumentId"]);
                                        list.Fields.Add("TitleName", SPFieldType.Text, false);
                                        SetFieldProperties(list.Fields["TitleName"]);
                                        list.Fields.Add("StageName", SPFieldType.Text, false);
                                        SetFieldProperties(list.Fields["StageName"]);
                                        list.Fields.Add("IsDeleted", SPFieldType.Boolean, false);
                                        SetFieldProperties(list.Fields["IsDeleted"]);
                                        list.Fields["IsDeleted"].DefaultValue = "0";
                                        list.Fields["IsDeleted"].Update();
                                        list.Fields.Add("Checked Out To", SPFieldType.User, false);
                                        SetFieldProperties(list.Fields["Checked Out To"]);
                                        //   list.Fields[0].ShowInDisplayForm
                                        SPView defaultView = list.DefaultView;
                                        defaultView.ViewFields.Add("DocumentType");
                                        defaultView.ViewFields.Add("FileFormat");
                                        defaultView.ViewFields.Add("DocumentId");
                                        defaultView.ViewFields.Add("TitleName");
                                        defaultView.ViewFields.Add("StageName");
                                        defaultView.ViewFields.Add("IsDeleted");
                                        defaultView.ViewFields.Add("Checked Out To");
                                        defaultView.Update();
                                        list.Update();
                                    }
                                }
                            }
                            flag = true;
                        }
                }
               }

            }});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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