wss3 sdk学习笔记二:建立一个SharePoint网站应用
一、在VS2005中新建立一个项目或者网站
二、在CS文件中记得添加以下代码:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
四、访问方法:
例如本人的测试项目访问地址如下:http://gzcxxgc14t/sites/wss3/_layouts/wss3ApplicationWeb/default.aspx
OK,就这么简单!
附上一些常用代码:
返回一个网站集下的全部网站以及网站下面的列表名称的代码:
新建立一个子网站的代码:
删除一个子网站的代码:
新建立一个网站集的代码:
二、在CS文件中记得添加以下代码:
using Microsoft.SharePoint;
三、把项目或者网站的目录拷贝到以下路径:C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
四、访问方法:
http://
Server_Name/[sites/][
Site_Name/]_layouts/
Web_Application_Name/Default.aspx
.例如本人的测试项目访问地址如下:http://gzcxxgc14t/sites/wss3/_layouts/wss3ApplicationWeb/default.aspx
OK,就这么简单!
附上一些常用代码:
返回一个网站集下的全部网站以及网站下面的列表名称的代码:
SPSite mySite = SPContext.Current.Site;
SPWebCollection subSites = mySite.AllWebs;
for (int i=0;i<subSites.Count;i++)
{
SPListCollection lists = subSites[i].Lists;
for (int j=0;j<lists.Count;j++)
{
Response.Write(SPEncode.HtmlEncode(subSites[i].Title)
+ " :: " + SPEncode.HtmlEncode(lists[j].Title) + "<BR>");
}
}
SPWebCollection subSites = mySite.AllWebs;
for (int i=0;i<subSites.Count;i++)
{
SPListCollection lists = subSites[i].Lists;
for (int j=0;j<lists.Count;j++)
{
Response.Write(SPEncode.HtmlEncode(subSites[i].Title)
+ " :: " + SPEncode.HtmlEncode(lists[j].Title) + "<BR>");
}
}
新建立一个子网站的代码:
SPWeb mySite = SPContext.Current.Web;
SPWebCollection subSites = mySite.Webs;
string currentTemplate = mySite.WebTemplate;
string siteUrl = TextBox1.Text.ToString();
string siteTitle = TextBox2.Text.ToString();
string siteDescription = TextBox3.Text.ToString();
subSites.Add(siteUrl, siteTitle, siteDescription, 1033,
currentTemplate, true, false);
SPWebCollection subSites = mySite.Webs;
string currentTemplate = mySite.WebTemplate;
string siteUrl = TextBox1.Text.ToString();
string siteTitle = TextBox2.Text.ToString();
string siteDescription = TextBox3.Text.ToString();
subSites.Add(siteUrl, siteTitle, siteDescription, 1033,
currentTemplate, true, false);
删除一个子网站的代码:
string deleteSite = TextBox1.Text.ToString();
SPSite mySite = SPContext.Current.Site;
SPWebCollection sites = mySite.AllWebs;
sites.Delete(deleteSite);
SPSite mySite = SPContext.Current.Site;
SPWebCollection sites = mySite.AllWebs;
sites.Delete(deleteSite);
新建立一个网站集的代码:
SPWebApplication webApplication = SPContext.Current.Site.WebApplication;
SPSiteCollection siteCollections = webApplication.Sites;
siteCollections.Add("http://Server_Name/sites/Site_Collection_Name",
"User_Name","User_Email ");
SPSiteCollection siteCollections = webApplication.Sites;
siteCollections.Add("http://Server_Name/sites/Site_Collection_Name",
"User_Name","User_Email ");