您的位置:首页 > 运维架构 > 网站架构

js 获取 sharepoint 2010 网站信息(title,id,language……)

2012-06-05 17:36 429 查看
<scripttype="text/ecmascript"language="ecmascript">

vartargetWeb;

functionrunCode(){
//获取当前
varclientContext=newSP.ClientContext.get_current();//SP.ClientContext(‘url’)相对地址
targetWeb=clientContext.get_web();
clientContext.load(targetWeb);
clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded),Function.createDelegate(this,this.onQueryFailed));
}

functiononQuerySucceeded(){//获取信息成功的处理函数
//获取网站的信息
varmessage="Webretrieved:";
message+="\nTitle:"+targetWeb.get_title();//标题
message+="\nID:"+targetWeb.get_id();
message+="\nLanguage:"+targetWeb.get_language();
message+="\nUIVersion:"+targetWeb.get_uiVersion();
message+="\nDescription:"+targetWeb.get_description();//描述
message+="\nCreated:"+targetWeb.get_created();//创建时间
alert(message);
}

functiononQueryFailed(sender,args){//获取信息失败的处理函数
alert('Requestfailed.\nError:'+args.get_message()+'\nStackTrace:'+args.get_stackTrace());
}
runCode();
</script>
效果如图:


添加列表,成功后获取站点的所有列表:
代码如下:
<scripttype="text/ecmascript">
varlistCollection;
functionrunCode(){
varclientContext=newSP.ClientContext.get_current();//获取客户端对象上下文
if(clientContext!=undefined&&clientContext!=null){
varweb=clientContext.get_web();//获取当前网站
this.listCollection=web.get_lists();//获取列表集合

//Specifythetitleandtemplateofthenewlists.
varlci1=newSP.ListCreationInformation();//新建一个列表
lci1.set_title('NewAnnouncements');//设置列表的名字
lci1.set_templateType(SP.ListTemplateType.announcements);//设置列表类型
this.listCollection.add(lci1);

varlci2=newSP.ListCreationInformation();
lci2.set_title('OldAnnouncements');
lci2.set_templateType(SP.ListTemplateType.announcements);
this.listCollection.add(lci2);

clientContext.load(this.listCollection);
clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded),Function.createDelegate(this,this.onQueryFailed));//执行异步操作
}
}

functiononQuerySucceeded(){//成功处理函数
varlistInfo='Listsonthecurrentsite:'+'\n\n';
varlistEnumerator=this.listCollection.getEnumerator();//实例化一个列表枚举器
while(listEnumerator.moveNext()){//循环输出列表的名字
varlist=listEnumerator.get_current();
listInfo+=list.get_title()+'\n';
}
alert(listInfo);
}

functiononQueryFailed(sender,args){//失败处理函数
alert('Requestfailed.'+args.get_message()+'\n'+args.get_stackTrace());
}
runCode();
</script>
效果如图所示:红圈是新创建的两个列表项

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}




.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: