文章主旨:获取SharePoint 2010 中SPFarm, SPWebApplicationCollection, SPWebApplication, SPSiteCollection, SPSite, SPWebCollection, SPWeb, SPListCollection, SPList级别对象的基本操作。【更在于方便自己在工作中的记忆与学习】

对SharePoint的基本操作有很多,要熟悉它的API不是一朝一夕就能搞定的事情,这篇文章主要是记录如何获取SharePoint中List级别以上对象的获取。下面是我自己测试的代码,希望对你有所帮助:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.SharePoint;
6 using Microsoft.SharePoint.Administration;
7
8 namespace GetCommonLevelObject
9 {
10 class CommonLevelObject
11 {
12 //在运行这部分代码之前要保证:
13 //1:本机已经成功安装SharePoint
14 //2:本项目里已经添加了SharePoint的服务(并且命名空间添加:SharePoint和SharePoint.Administration)
15 //3:本项目的(属性)Platform target一定是 x64 或 any cpu,(若是x86则会得不到SharePoint的对象)同时 Application的Target Framework == .NET Framework 3.5
16 staticvoid Main(string[] args)
17 {
18 //获取本地SharePoint的Farm(并且输出Farm的名字)
19 SPFarm mLocalFarm = SPFarm.Local;
20 string mLocalFarmName = mLocalFarm.DisplayName;
21 Console.WriteLine("The Local SPFarm name is: {0}", mLocalFarmName);
22
23
24 //获取WebApplicationCollection
25 SPWebApplicationCollection mWebAppCol = SPWebService.ContentService.WebApplications;
26 //遍历WebApplicationCollection中所有的WebApp
27 foreach (SPWebApplication webapp in mWebAppCol)
28 {
29 Console.WriteLine("The name of SPWebApplication is: {0}", webapp.Name);
30 }
31 //获取WebApplicationCollection中某个特定的WebApp
32 SPWebApplication mWebApp = mWebAppCol["SharePoint - 12345"]; //下标为WebApp的名字或Guid
33
34
35 //获取某个WebApp下的SiteCollection
36 SPSiteCollection mSiteCol = mWebApp.Sites;
37 //遍历SiteCollection中所有的Site(即:手动创建的每一个SiteCollection)
38 foreach (SPSite site in mSiteCol)
39 {
40 Console.WriteLine("The name of SPSite is: {0}", site.Url); //site没有Name和Title属性
41 }
42 //获取SiteCollection中某个特定的Site【下标为Site的Server_Relative Url或是在SiteCollection中的序号】
 43 SPSite mSite = mSiteCol["sites/MyTeamSiteCollection1"];
44
45
46 //获取某个Site下的WebCollection(其中包括该Site的RootWeb)
47 //(注:Web的Name是Url上显示的名字;Title是页面显示的名字。手动创建时都可以填写)
48 SPWebCollection mWebCol = mSite.AllWebs;
49 foreach (SPWeb web in mWebCol)
50 {
51 Console.WriteLine("The title of web is: {0}", web.Title);
52 Console.WriteLine("The name of web is: {0}", web.Name);
53 }
54
55 //获得某个Site的RootWeb
56 SPWeb rootWeb = mSite.RootWeb;
57 //获取某个RootWeb(Web)下的WebCollection(其中不包含该RootWeb(Web))
58 SPWebCollection mAnotherWebCol = rootWeb.Webs;
59 foreach (SPWeb web in mAnotherWebCol)
60 {
61 Console.WriteLine("The title of web is: {0}", web.Title);
62 Console.WriteLine("The name of web is: {0}", web.Name);
63 }
64
65 //获取WebCollection中某个特定的Web
66 SPWeb mWeb = mWebCol["MyTeamSite1"];
67 //获取某个Web下的SPListCollection(之后的以此类推)
68 //【注:Site没有.Lists属性,但是Web有.Lists属性】
69 SPListCollection mListCol = mWeb.Lists;
70 foreach (SPList list in mListCol)
71 {
72 Console.WriteLine("The title of the list is: {0}", list.Title); //List没有Name,但是有Title
73 }
74 SPList mList = mListCol["NewCustomList1"];
75
76 }
77 }
78 }
79

关于所有List级别以下(Item,Folder,File等等)对象的获取以后再详细介绍。

SharePoint 2010 各个常用级别对象的获取相关推荐

  1. sharepoint 2010项目中,ashx页面获取SPContext.Current 为null的原因和解决方法

    //错误的写法 public void ProcessRequest(HttpContext context) {SPSecurity.RunWithElevatedPrivileges(delega ...

  2. 在SharePoint 2010中创建网站的权限级别

    转:http://www.360sps.com/Item/CreatePermissionLevels.aspx 权限级别是SharePoint 2010新增加的功能,使我们对权限的设置又提高了一个层 ...

  3. sharepoint 2010 使用WinForm获取 SPSite对象

    在sharepoint 2010中,有时候我们想利用WinForm程序去获取某sharepoint站点的信息,但是对于刚接触的人会有点问题. 一般情况下我们会使用Visual Studio 2010新 ...

  4. PowerShell在SharePoint 2010自动化部署中的应用(1)--代码获取

    由于项目需要,要把项目组成员中每天的工作整合到一起.每天手动部署很是费时费力.于是有了是否能利用PowerShell进行自动化部署的想法,正好也有机会学习一下PowerShell. 先交代一下项目背景 ...

  5. sharepoint 2010 获取讨论板话题的所有评论回复信息 Get all replies

    前面提到在sharepoint 2010 如何给讨论板(Discussion)话题添加回复(Reply)信息(Message) 以下是如何通过程序,获取这些所有回复信息. SPSecurity.Run ...

  6. 了解 SharePoint 2010 开发中的关键点

    **摘要:**了解为 Microsoft SharePoint 2010 规划和开发业务解决方案时必须做出的关键点. 上次修改时间: 2012年3月13日 适用范围: Business Connect ...

  7. 在 SharePoint 2010 中访问数据

    数据访问的关键方法有哪些? | 使用查询类 | 使用 SPQuery | 使用 SPSiteDataQuery | 使用 LINQ to SharePoint | LINQ to SharePoint ...

  8. SharePoint 2010文档库批量下载文档的实现

    在SharePoint 2010文档库中,结合单选框,在Ribbon中提供了批量处理文档的功能,比如,批量删除.批量签出.批量签入等,但是,很遗憾,没有提供批量下载,如图: 若选中多个文档后,会发现D ...

  9. SharePoint 2010中的客户端AJAX应用——ASP.NET AJAX模板

    WCF Data Services是SharePoint 2010中一个极具吸引力的新特性.然而,因为它的强大,直接对其进行编程仍然会有点痛苦.幸运的是,一个新的相关技术 -- ASP.Net AJA ...

最新文章

  1. 数据库-DQL练习(附答案)
  2. java jsp总结
  3. tcp前4字节消息长度_网络基础篇之TCP
  4. 爬虫python软件准备_工具准备的差不多了,接下来就是python爬虫的封装了
  5. 面试题58 - II. 左旋转字符串
  6. java用中点画圆法_OpenGL通过中点法绘制直线和圆
  7. 刚刚,贺建奎回应一切:如果是我孩子,我会第一个去试验
  8. WebView 简介
  9. 瀑布模型,快速原型模型,增量模型,螺旋模型以及敏捷开发模型的相关概念
  10. Google SPDY介绍
  11. Word中在小方框里面打勾的正确方法
  12. 白岩松:不平静,就不会幸福 幸福在哪里(代序)
  13. Android 仿支付宝搜索结果页,字符串部分文字显示高亮
  14. Linux创建share共享文件夹
  15. 考研计算机C语言算法视频,计算机算法考研视频哪个好
  16. python对投标_有关招标投标签订合同的说法,正确的是(      ) 。
  17. 计算机无法连接网络显示错误651,电脑宽带连不上显示错误651是什么意思?
  18. 卷积 反卷积 上采样 下采样 区别
  19. UE5编辑器中C++代码编译按钮在哪里?
  20. 喷淋塔废水除臭剂降低排放口废气浓度

热门文章

  1. 全球及中国软磁镍合金行业供需前景与投资策略研究报告2022版
  2. 中科微研携手-农业大健康·李喜贵:从玉农业谋定功能性农业
  3. 摸清全国农村集体家底-农业大健康:产权改革谋定清产核资
  4. vscode 将本地项目上传到github、从github克隆项目以及删除github上的某个文件夹
  5. OMG: daily scrum six
  6. java 打印box文件
  7. 设计模式のObserver Pattern(观察者模式)----行为模式
  8. lucene之创建索引代码
  9. 把CentOS启动进度条替换为详细信息
  10. TCP连接之未连接队列的理解[转]