若是大蝦,直接跳過吧
一 基礎準備
1. Sharepoint2007物件模型系列
一般開發人員或者初學者可能一般接觸的對象都是SPSite層級一下的
這裡主要有 SPFarm,SPService, SPApplicationPool,SPWebApplication等等,當然還有SPFeatureDefinition,SPSolution等等
2.Windows SharePoint Services 3.0 的管理物件模型
來自MSDN的參考,
幾個方面來闡述wss的階層
Windows SharePoint Services 的內容階層
Windows SharePoint Services 的內容階層
Windows SharePoint Services 的服務層次結構
3.How to Create new application pool and change App Pool of SharePoint Website
這裡我們要知道的是,如果直接從iis裡建立的應用程式集區是不會被sharepoint識別的
二 邏輯
1.建立應用程式集區(SPApplicationPool)--> 2.建立應用程式(SPWebApplication)--> 3.建立網站集合(SPSite)
其中較為麻煩的為 建立應用程式
1.建立應用程式集區(SPApplicationPool)
建立應用程式集
public SPApplicationPool CreateNewPool(string poolName)
{
SPWebService webService = farm.Services.GetValue<SPWebService>();
SPApplicationPool pool = new SPApplicationPool(poolName, webService);
pool.CurrentIdentityType = IdentityType.SpecificUser;
pool.Username = @"sharepoint2007\mossadmin";
pool.Password = "abc-*/123";
pool.Update();
pool.Deploy();
return pool;
}
2. 建立應用程式
代碼
public SPWebApplication CreateWebApplication(string appName, SPApplicationPool pool)
{
int port = 2005;
SPWebApplicationBuilder webAppBlder = new SPWebApplicationBuilder(farm);
//設定IIS網站屬性:
webAppBlder.Id = Guid.NewGuid();
webAppBlder.Port = port;
webAppBlder.RootDirectory = new System.IO.DirectoryInfo(@"C:\Inetpub\wwwroot\wss\VirtualDirectories\" + port.ToString());
//設定應用程式集區的屬性:
//主要是指定IIS應用程式集區的名稱和訪問使用者名稱、密碼等屬性
webAppBlder.ApplicationPoolId = "your application pool name";
//web應用程式的安全性設定:
//在這裡設定為使用NTLM驗證,在Sharepoint中使用了NTLM和Kerberos兩種驗證方式,Kerberos相對來說比較複雜一點的。不使用SSL,不允許匿名訪問
webAppBlder.UseNTLMExclusively = true;
webAppBlder.AllowAnonymousAccess = false;
webAppBlder.UseSecureSocketsLayer = false;
//設定Server Load Balancer的 URL:
webAppBlder.DefaultZoneUri = new Uri("http://mossserver:2005");
//設定web應用程式的資料庫屬性:
//這裡資料庫使用者名稱設為空白值,表示使用Windows整合認證的方式
webAppBlder.CreateNewDatabase = true;
webAppBlder.DatabaseServer = "mossserver";
webAppBlder.DatabaseName = "TestApp2005";
webAppBlder.DatabaseUsername = string.Empty;
//建立Web應用程式:
//實際的在Sharepoint的伺服器陣列中建立一個web應用程式
SPWebApplication webApp = webAppBlder.Create();
//設定Web應用程式的常規屬性:
//這裡的時區45表示的是GMT+08:00北京時區
//這裡的設定主要是類比sharepoint管理中心裡<Web應用程式常規設定>中的配置
webApp.DefaultTimeZone = 45;
webApp.Name = appName;
webApp.Update();
//建立 IIS Web 應用程式和應用程式集區:
webApp.Provision();
return webApp;
}
3. 建立網站集合
public SPSite CreateSite(SPWebApplication webApp, string siteUrl)
{
return webApp.Sites.Add(siteUrl, "", "", 2052, "BDR#0", @"sharepoint2007\mossadmin", "", "mossadmin@hh.com");
}
其中 BDR#0 為網站模板,你可以參考 這裡
希望可以給大家帶來一些協助,也希望大家給我帶來協助。