在SharePoint2010可见Web部件中使用Web Service获得所有列表 Get all lists using Web Service in SharePoint 2010 Visual Web Part

本文中,你将看到如何使用Web Service(_vti_bin/lists.asmx)获得所有列表,以及在SharePoint 2010 Visual Web部件中显示列表标题和描述。

Create an Empty SharePoint Project using Visual Studio 2010

1. 以管理员身份打开VS2010。
2. 新建项目。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
3. 选择空白SharePoint项目。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
4. 输入GetList作为项目名,点击确定。
5. 选择调试的本地站点,部署为场解决方案。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
6. 点击完成。

Add Visual Web Part to the Empty SharePoint Project

1. 在解决方案管理其中,右击解决方案,点击添加。
2. 点击新项目。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
3. 选择Visual Web部件。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
4. 输入GetList作为Web部件名,点击添加。

Add Web Reference to the solution

1. 右击“引用”文件夹,点击“添加服务引用”。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
2. 点击“高级”按钮。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
3. 点击“添加Web引用”。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
4. 在URL部分,输入lists web service URL并按下回车键。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
5. 输入Web Reference名称,点击“添加引用”按钮。
6. Web Reference成功被添加。

GetListUserControl.ascx

1. 用以下代码代替GetListUserControl.aspx:
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part

GetListUserControl.ascx.cs

1. 添加下列命名空间:
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
2. 用一下代码代替GetListUserControl.ascx.cs:
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part

Deploy the solution:

1. 生成解决方案。
2. 按下F5。

Create SharePoint 2010 Visual Web Part in the SharePoint site:

1. 打开SharePoint站点。
2. 进入网站操作--编辑页面。
3. 编辑工具--插入--Web部件。
4. 在类别Custom选择GetList。
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part
5. 点击添加。
6. Visual Web部件显示了所有列表标题和描述如下:
在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part

Summary:

到这里你已经看到了如何使用Web Service(_vti_bin/lists.asmx)获得所有列表,并在SharePoint 2010 Visual Web部件中显示所有列表标题和描述。

原文链接:

http://www.c-sharpcorner.com/UploadFile/anavijai/get-all-lists-using-web-service-in-sharepoint-2010-visual-we/

本机截图:

在SharePoint2010可见Web部件中使用Web Service获得所有列表
Get all lists using Web Service in SharePoint 2010 Visual Web Part

故障分析:

原文在Web Service引用方面出现问题,导致本机不能导入Web部件,或者出现应用程序错误等。
我将Web Service引用的地址改写为(本机为例):http://本机IP/_vti_bin/Lists.asmx。(请用你自己的IP替换掉例子中的本机IP)。相应的代码中对Web Service的引用也要进行替换。