您的位置:首页 > 其它

处方1-1使用对象模型新建站点集

2008-12-16 20:34 501 查看
SharePoint2007 Development Recipes 读书笔记 处方1-1
使用对象模型新建站点集
关键代码:
private static int AddSiteCollection(string[] args) {
try {
// Get a handle to the root site on server
string[] arrSitePath = args[0].Split('/');
string strServerPath = (arrSitePath[0]
+ ("//" + arrSitePath[2]));
SPSite site = new SPSite(strServerPath);
// Get the list of site collections for the web
// application
SPSiteCollection siteCollection =
site.WebApplication.Sites;
// Step 3: Add the site collection
// args(0) = Site url
// args(1) = Title
// args(2) = Description
// args(3) = Web template
// args(4) = Owner login
// args(5) = Owner name
// args(6) = Owner email
siteCollection.Add(args[0], args[1], args[2], 1033,
args[3], args[4], args[5], args[6]);
// Step 5: Confirm site collection information
Console.WriteLine();
Console.WriteLine(("Site collection \'"
+ (args[0] + "\' successfully created.")));
Console.WriteLine();
DisplayParams(args);
// Release memory used by SPSite object
site.Dispose();
return 0;
}
说明:通过主站点的URL取得SPSite对象然后通过SPSite.WebApplication.Sites属性得到SPSiteCollection对象,最后通过SPSiteCollection.Add()方法即可以在主站点上添加网站集。

限制:由于SPSiteCollection.Add()方法的安全限制,导致程序只能在SharePoint服务器场中的前端Web服务器上执行,且必须要在有相应权限的用户登陆情况下才能正常工作,所以不是真正意义上的Web服务。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  模型 对象 SharePoint