标签:sharepoint 对象模型
SharePoint中对象的层次结构,又包含一次类推为
webApplication->SPSite->SPweb->SPList->SPItem。也就是webApp应用程序最大,其包括网站集SPSite,网站集包括网站Web,再往下有列表SPList,列表项有SPItem.
对sharePoint对象某型几个操作。
服务器端代码:
应用程序下的所有网站集
foreach (SPSite spSite inSPContext.Current.Site.WebApplication.Sites)
{
//应程序下的所有网站集
}
当前站点下的网站集
<span style="font-size:18px;">SPSite spSite = SPContext.Current.Site;</span>
网站集下的根网站
<span style="font-size:18px;">SPWeb spWeb =spSite.RootWeb;</span>
网站集下的所用网站
<span style="font-size:18px;">foreach (SPWeb spSite in spSite)
{
//应程序下的所有网站集
}</span>
列表对象,(这里有个重点很多时候需要变量一定类型的列表)文档库的类型是101
<span style="font-size:18px;">foreach (SPList spList in spWeb.Lists)
{
if ((int)spList.BaseTemplate== 101)
{//遍历所有文档库类的列表
}
}</span>
读取每行中字段的信息。
这里举得例子是:通过新建ribbon,中的js读取这个字段是谁创建的。
<span style="font-size:18px;"> var userAdress;
var userName;
var id = GetItemID();
function GetItemID() {
var selectedItems =SP.ListOperation.Selection.getSelectedItems();
var count =CountDictionary(selectedItems);
if (count > 0) {
returnselectedItems[0].id;
} else {
return null;
}
}
functionOnQuerySucceeded(sender, args) {
this.userAdress=listItem.get_item('Created_x0020_By');
this.userName=listItem.get_item('Author').$2e_1;
alert(this.userAdress+' '+this.userName)
}
function OnQueryFailed() {
}
if (id != null) {
context =SP.ClientContext.get_current();
var listId =SP.ListOperation.Selection.getSelectedList();
var corporateCatalog =context.get_web().get_lists().getById(listId);
listItem =corporateCatalog.getItemById(id);
context.load(listItem);
context.executeQueryAsync(OnQuerySucceeded, OnQueryFailed);
}</span>这几个应用都是作者开发中真实用到的小例子,希望能给大家帮助。希望能认识到技术上的知己,我是一个爱计算机编程的自学者。
标签:sharepoint 对象模型
原文地址:http://blog.csdn.net/jielizhao/article/details/38871989