private void CreateSiteCollection(SPWebApplication webApp) { string sitCollName = ""; string url = ""; string baseName = ""; findAvailableSiteCollectionName(webApp, out sitCollName, out url, out baseName); Owner.IncrementCurrentTaskProgress("Creating site collection '" + url + "'"); SPSiteCollection siteCollections = webApp.Sites; SPSite site = siteCollections.Add("/sites/" + url, WorkingDefinition.SiteCollOwnerLogin, WorkingDefinition.SiteCollOwnerEmail); SPWeb web = site.RootWeb; web.Title = sitCollName; web.Update(); SiteCollInfo siteCollInfo = new SiteCollInfo(); siteCollInfo.URL = site.Url; Owner.WorkingSiteCollections.Add(siteCollInfo); }
private void InitializeSiteAtManagedPath(string managedPath) { var defaultPortWebApp = this.GetDefaultPortWebApp(); SPContentDatabase testContentDatabase = this.EnsureTestContentDatabase(defaultPortWebApp); var prefixCollection = defaultPortWebApp.Prefixes; if (!prefixCollection.Contains(managedPath)) { // The hostname-site collection's prefix may still exist // if a test run was interrupted previously. prefixCollection.Add(managedPath, SPPrefixType.ExplicitInclusion); } // Flag so dispose will remove the managed path when the site collection is deleted this.ManagedPathCreated = managedPath; var siteUrl = defaultPortWebApp.GetResponseUri(SPUrlZone.Default) + managedPath; SPSiteCollection sites = testContentDatabase.Sites; SPSite existingSite = sites.FirstOrDefault(site => site.Url == siteUrl); if (existingSite != null) { existingSite.Delete(); existingSite.Dispose(); // Refresh Sites collection sites = testContentDatabase.Sites; } var newSite = sites.Add(siteUrl, Environment.UserName, "*****@*****.**"); this.SiteCollection = newSite; }
private static int CreateSiteCollection() { try { string srvUrl = "http://sharepointserve"; using (SPSite site = new SPSite(srvUrl)) { // current collection SPSiteCollection coll = site.WebApplication.Sites; XDocument definition = XDocument.Load("SiteDefinition.xml"); XElement root = definition.Element("SiteDefinition"); SPSite newSite = coll.Add( root.Element("Url").Value, root.Element("Title").Value, root.Element("Description").Value, Convert.ToUInt32(root.Element("LCID").Value), (String.IsNullOrEmpty(root.Element("WebTemplate").Value) ? null : root.Element("WebTemplate").Value), root.Element("OwnerLogin").Value, root.Element("OwnerName").Value, root.Element("OwnerEmail").Value ); return(0); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(1); } }
private void InitializeSite(string hostName, string templateName, uint lcid) { var defaultPortWebApp = this.GetDefaultPortWebApp(); SPContentDatabase testContentDatabase = this.EnsureTestContentDatabase(defaultPortWebApp); SPSiteCollection sites = testContentDatabase.Sites; SPSite existingSite = testContentDatabase.Sites.FirstOrDefault(site => site.Url == hostName); if (existingSite != null) { existingSite.Delete(); existingSite.Dispose(); // Refresh Sites collection sites = testContentDatabase.Sites; } SPSite newSite = sites.Add( hostName, "Dynamite Test", "Integration test temporary site", lcid, templateName, Environment.UserName, "Dynamite Test Agent", "*****@*****.**", Environment.UserName, "Dynamite Test Agent", "*****@*****.**", true); this.SiteCollection = newSite; }
public SPSiteInstance Add(string siteUrl, string ownerLogin, string ownerEmail) { var result = m_siteCollection.Add(siteUrl, ownerLogin, ownerEmail); return(result == null ? null : new SPSiteInstance(Engine.Object.InstancePrototype, result)); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { try { string secondaryLogin = GetEmptyAsNull(SecondaryOwnerLogin); string secondaryDisplayName = GetEmptyAsNull(SecondaryOwnerDisplayName); string secondaryEmail = GetEmptyAsNull(SecondaryOwnerEmail); string templateID = GetEmptyAsNull(TemplateID); string description = GetNullAsEmpty(SiteDescription); string title = GetNullAsEmpty(SiteTitle); SPSiteCollection sites = GetSitesCollection(); SPSecurity.RunWithElevatedPrivileges(delegate() { if (IsolateInNewContentDB) { using (SPSite site = sites.Add(SiteURL, title, description, LCID, templateID, PrimaryOwnerLogin, PrimaryOwnerDisplayName, PrimaryOwnerEmail, secondaryLogin, secondaryDisplayName, secondaryEmail, DBServer, NewContentDBName, null, null)) { CapContentDB(site); Result = site.Url; } } else { using (SPSite site = sites.Add(SiteURL, title, description, LCID, templateID, PrimaryOwnerLogin, PrimaryOwnerDisplayName, PrimaryOwnerEmail, secondaryLogin, secondaryDisplayName, secondaryEmail)) { Result = site.Url; } } string message = "Provisioning Site Collection " + SiteTitle + " at " + SiteURL; WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message); }); } catch (Exception ex) { WorkflowHistoryLogger.LogError(executionContext, UserID, ex); return(ActivityExecutionStatus.Faulting); } return(ActivityExecutionStatus.Closed); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication; SPSiteCollection sites = webApplication.Sites; if (sites["sites/training"] == null) { SPSite trainingSite = sites.Add("sites/training", "CORP\\Administrator", "*****@*****.**"); trainingSite.Dispose(); } }
public void hstCreateSite(string webAppURL, string strURL, string strTitle, string strDesc, uint nLCID, string strTemplate, string strOwnerLogin1, string strOwnerName1, string strOwnerEmail1, string strOwnerLogin2, string strOwnerName2, string strOwnerEmail2, bool hhMode) { System.Uri srvrUri = new System.Uri(webAppURL); SPWebApplication webApp = SPWebApplication.Lookup(srvrUri); SPSiteCollection siteColl = webApp.Sites; SPSite oSite = null; try { // If the secondary owner information is not provided, make sure it's null if (String.IsNullOrEmpty(strOwnerLogin2)) { strOwnerLogin2 = null; } if (String.IsNullOrEmpty(strOwnerName2)) { strOwnerName2 = null; } if (String.IsNullOrEmpty(strOwnerEmail2)) { strOwnerEmail2 = null; } if (String.IsNullOrEmpty(strDesc)) { strDesc = null; } if (String.IsNullOrEmpty(strTitle)) { strTitle = null; } if (String.IsNullOrEmpty(strTemplate)) { strTemplate = null; } // add site to the site collection oSite = siteColl.Add(strURL, strTitle, strDesc, nLCID, strTemplate, strOwnerLogin1, strOwnerName1, strOwnerEmail1, strOwnerLogin2, strOwnerName2, strOwnerEmail2, true); } finally { // dispose object if (oSite != null) { oSite.Dispose(); } } }
private SPSite AddSite(SPSiteCollection sites, Site siteToAdd, SitesConfiguration configuration) { var newSite = sites.Add( siteToAdd.Name, siteToAdd.Title, siteToAdd.Description, siteToAdd.Locale, null, configuration.SitesOwner, configuration.SitesOwner, string.Empty); /*logger.Debug( string.Format( "Loading template: {0} from package: {1} in folder: {2}", site.WebTemplate.Name, site.WebTemplate.PackageFileName, configuration.TemplatesDirectory));*/ LoadTemplateFromPackage( newSite, siteToAdd.WebTemplate.PackageFileName, configuration.TemplatesDirectory); /*logger.Debug(string.Format("Done. Loading template: {0}", site.WebTemplate.Name));*/ /*logger.Debug(string.Format( "Applying template: {0} to empty site: {1}", site.WebTemplate.Name, site.Name));*/ ApplyWebTemplate(GetRootWeb(newSite), siteToAdd.WebTemplate.Name); /*logger.Debug(string.Format( "Done. Applying template: {0} to site: {1}", site.WebTemplate.Name, site.Name));*/ return newSite; }
/// <summary> /// /// </summary> /// <param name="webApplicationURL"></param> /// <param name="siteName"></param> /// <param name="siteTitle"></param> /// <param name="siteDesc"></param> /// <param name="siteLanguage"></param> /// <param name="templateName"></param> /// <param name="ownerLoginName"></param> /// <param name="ownerName"></param> /// <param name="ownerEmail"></param> /// <returns></returns> public bool CreateSiteCollection( String webApplicationURL, string siteName, string siteTitle, string siteDesc, int siteLanguage, string templateName, string ownerLoginName, string ownerName, string ownerEmail ) { bool isSiteCreated = false; try { LoggingService.LogErrorInULS("RSG.Inside.SPSiteCol.ExternalService - CreateSiteCollection - Start"); LoggingService.LogErrorInULS("SIte Info: " + "\nWebApplication URL: " + webApplicationURL + "\nSiteName: " + siteName + "\nSiteTitle: " + siteTitle + "\nSiteDesc: " + siteDesc + "\nSiteLanguage: " + siteLanguage + "\nTemplateName: " + templateName + "\nownerLoginName: " + ownerLoginName + "\nownerName: " + ownerName + "\nownerEmail: " + ownerEmail ); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite siteCollectionOuter = new SPSite(webApplicationURL)) { SPWebApplication webApp = siteCollectionOuter.WebApplication; LoggingService.LogErrorInULS("SiteCreationActivity :" + webApplicationURL + siteName + templateName + siteLanguage); SPSiteCollection siteCollection = webApp.Sites; UInt32 lang = Convert.ToUInt32(siteLanguage); SPWebTemplateCollection myTemplates = siteCollectionOuter.RootWeb.GetAvailableWebTemplates(lang); SPWebTemplate reqTemplate = myTemplates[templateName]; if (reqTemplate != null) { using (SPSite site = siteCollection.Add("sites/" + siteName, siteTitle, siteDesc, lang, reqTemplate.Name, ownerLoginName, ownerName, ownerEmail)) { isSiteCreated = true; try { site.Features.Add(new Guid("F6924D36-2FA8-4f0b-B16D-06B7250180FA"), true); } catch (Exception expub) { LoggingService.LogErrorInULS("Publishing Feature Activation Issue" + expub.ToString()); } try { site.Features.Add(new Guid("c7c893fd-9cbe-4f40-ad1d-990f69978203"), true); } catch (Exception expub) { LoggingService.LogErrorInULS("Site Provision Feature Activation Issue" + expub.ToString()); } } } } }); LoggingService.LogErrorInULS("RSG.Inside.SPSiteCol.ExternalService - CreateSiteCollection - End"); } catch (Exception ex) { LoggingService.LogErrorInULS("RSG.Inside.SPSiteCol.ExternalService CreateSiteCollection Issue :" + ex.Message); } return(isSiteCreated); }