sps编程模型中打开站点的几种方法

打开站点的几种方法

1、如果你想打开的是你这个WEBPart所在的站点,直接使用SPWeb和SPControl打开。

注意:想要引用Microsoft.sharpoint和Microsoft.Sharpoint.WebControls

SPWeb mySite=SPControl.GetContextWeb(Context);

2、如果要访问当前虚拟服务器的其他站点

SPWeb site=SPControl.GetContextSite(Context).AllWebs[@"/C1/文档中心/"];

也可以:

SPSite myWeb=SPControl.GetContextSite(Context);

SPWeb mySite=myWeb.AllWebs[@"/C1/文档中心/"];

3、访问不同虚拟服务器的不同站点

SPSite siteCollection=new SPSite(" http://zhouyi1095.test.net/ ");

SPWeb site=siteCollection.AllWebs[@"/C1/文档中心/"];

Published At
Categories with Web编程
Tagged with
comments powered by Disqus