ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Showing posts with label Sharepoint Site Collection. Show all posts
Showing posts with label Sharepoint Site Collection. Show all posts

Wednesday, May 9, 2012

How to create Site Collections from a Custom Web Template

Download project at here

How to create Site Collections from a Custom Web Template Programming

Open Visual Studio 2010.

Go to File => New => Project.

Select Empty SharePoint Project template from the installed templates.

Enter the Name “CreateSiteCollectionFromTemplate” and click Ok.

Right click on the solution and click on Add a new item.

Select the VisualWebPart template from the installed template.

Enter the Name as CreateSiteCollectionFromTemplate and click Ok.

Now the entire solution looks like following.


Open CreateSiteCollectionFromTemplateUserControl.ascx then drag and drop button follows as:
Double click to button and add reference:
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.IO;
using System.Linq;

Code in button Button1_Click
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.IO;
using System.Linq;

namespace CreateSiteCollectionFromTemplate.CreateSiteCollectionFromTemplate
{
    public partial class CreateSiteCollectionFromTemplateUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SPWebApplication spWebApplication = SPWebApplication.Lookup(new Uri("http://devsharepoint/"));
            using (SPSite spSite = spWebApplication.Sites.Add("/sites/HomeTemplate", "SharePoint", null, 1033, null, "administrator", "Administrator", "quochung211187@gmail.com"))
            {
                SPWeb rootWeb = spSite.RootWeb;
                // Get Solutions Gallery
                SPDocumentLibrary spDocumentLibrary = (SPDocumentLibrary)spSite.GetCatalog(SPListTemplateType.SolutionCatalog);
                // Upload Solution File with the Web Template (You must copy HomeTemplate.wsp to C:\Windows)
                SPFile solutionFile = spDocumentLibrary.RootFolder.Files.Add("HomeTemplate.wsp", File.ReadAllBytes(@"..\..\HomeTemplate.wsp"));
                // Activate Solution
                SPUserSolution spUserSolution = spSite.Solutions.Add(solutionFile.Item.ID);
                // Activate Features
                Guid solutionId = spUserSolution.SolutionId;
                // Activate Site Collection Features
                SPFeatureDefinitionCollection spFeatureDefinitionCollection = spSite.FeatureDefinitions;
                var features = from SPFeatureDefinition spFeatureDefinition
                               in spFeatureDefinitionCollection
                               where spFeatureDefinition.SolutionId.Equals(solutionId) && spFeatureDefinition.Scope == SPFeatureScope.Site
                               select spFeatureDefinition;
                foreach (SPFeatureDefinition feature in features)
                {
                    spSite.Features.Add(feature.Id, false, SPFeatureDefinitionScope.Site);
                }

                // Get Web Template
                SPWebTemplateCollection spWebTemplateCollection = spSite.RootWeb.GetAvailableWebTemplates(1033);
                SPWebTemplate webTemplate = (from SPWebTemplate spWebTemplate
                                             in spWebTemplateCollection
                                             where spWebTemplate.Title == "HomeTemplate"
                                             select spWebTemplate).FirstOrDefault();
                if (webTemplate != null)
                {
                    spSite.RootWeb.ApplyWebTemplate(webTemplate.Name);
                }
            }
        }
    }
}

Deploy Project
Go to central Admin create new Site collection then save that site collection to template and set name isHomeTemplate.wsp”, download that template and save at C:\Windows Folder
Go to the site where you have deployed the solution. Add webpart
Click button, automatically site collection is created follows as:
Check in Central Admin, see site collection is created by go to Central Admin => Application Management => View all site collections

Monday, May 7, 2012

How to create Site Collection in a specific Content Database


Add a new Content Database using Central Administration > Application Management > Content Databases > Add Content Database:
Type Database Name

NOTE! Make sure ”Maximum numbers of sites that can be created in this database” minus ”Current number of Sites” equals the largest number in which you want to add the new Site Collection:


View all site collection using Central Administration > Application Management > View all site collections  then you see root Web with WWS_Content database

And see /my (My Site) with WWS_Content database too

Go ahead and create a new Site Collection:
Title: My Home
URL: /sites/MyHome

Go back to the Content Database overview to see that the new Site Collection has been created in the new Content Database:

You can change “Number of sites before a warning event is generated” and “Maximum number of sites that can be created in this database” to make sure new Site Collections are added to the correct content database by click to WWS_Content_01 then edit
“Number of sites before a warning event is generated”: 1
Maximum number of sites that can be created in this database”: 2

“Number of sites before a warning event is generated” and “Maximum number of sites that can be created in this database” is changed

View all site collection using Central Administration > Application Management > View all site collections  then you will see new site collection with another content database


Creating site collection templates


In the article “How to create Site Collection in a specificContent Database” have a site collection was created is MyHome.
Go to Site > Site Actions > Click to Save site as template at Site Actions category
Type File name: MyHome, Template name: MyHome then click OK
Then save site as template successful, download that template and save to C:/ driver
Create site collection from template using Central Admin > Application Management > Create site collections
Title: My Home Template
URL: /sites/MyHomeTemplate
Select a template: <Select template later… > ! Important
Click to “Solution Gallery” link
Upload template “MyHome.wsp” in C:\ driver to solution then Active it
Go back before page you will see tab custom appear with template “MyHome” then click OK

At Visitors to this site: Use an existing group
Member of this site: Use an existing group
Owner of this site: Use an existing group
Then click OK
Result new site collection is created successful from template