欧非资源网:安全、免费、专业放心的资源下载站! 最新软件|软件分类

您的位置:欧非资源网 > 其他专区 > SharePoint > SharePoint 列表项通过自定义WebService读取

SharePoint 列表项通过自定义WebService读取

时间:2019-12-15 16:31作者:admin来源:未知人气:289我要评论(0)

给其他系统提供集成,发现SharePoint自带的WebService各种不好使,索性就自己写一点,也当做自己学习的记录了。当然内容比较简单,希望大侠们不要介意,也不要骂我啊。好了,进入正题吧。

1、 首先,使用VS2008新建一个WebService的项目,选择Asp.net Web服务应用程序,然后输入项目名称

clip_image002

2、 添加引用

添加Microsoft.SharePoint.dll文件的引用,因为我们需要使用SharePoint的对象模型来读取列表信息,Dll文件的位置是C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPIMicrosoft.SharePoint.dll

clip_image003

3、 添加函数

函数前面写上[WebMethod]标记,然后定义我们自己需要的方法,方法的参数和返回值,在方法里面,写我们的调用,我的代码就是个简单的例子,返回的也都是String类型,如果操作失败,则返回为空。

GetListItem(string WebUrl,string ListName,int ID)//获取列表项,传参分别为网站地址、列表名、ID

public string GetWebID(string WebUrl)//获取网站的WebID属性

[WebMethod]

public string GetWebID(string WebUrl)

{

try

{

SPSite site = new SPSite(WebUrl);

SPWeb web = site.OpenWeb();

return web.ID.ToString();

}

catch (Exception ex)

{

return "";

}

}

[WebMethod]

public string GetListItem(string WebUrl, string ListName, int ID)

{

try

{

SPSite site = new SPSite(WebUrl);

SPWeb web = site.OpenWeb();

SPListItem item = web.Lists[ListName].Items[ID];

String rt = "标题:" + item["Title"].ToString() + "内容:" + item["内容"].ToString();

return rt;

}

catch (Exception ex)

{

return "";

}

}

4、 发布WebService后测试

发布到IIS以后,打开我们的WebService,可以看到我们的自定义的两个方法,都在WebService中了。

clip_image004

5、 使用两个函数

我们可以分别测试下我们的两个函数,点击我们的函数,可以进入下面的界面,输入我们的参数,调用即可。

clip_image005

clip_image006

6、 调用结果

如果,可以看出我们调用的结果,下面第一张图是GetListItem(string WebUrl,string ListName,int ID)函数的,第二张图是GetWebID(string WebUrl)的结果。

clip_image008

clip_image010

小结

好了,我的博客记录今天就写到这里,环境大家多多提意见,打击我刚刚催生的小自信!

相关阅读 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database schema doesn't match the TargetSchema"的解决方案InfoPath Error “此文档库已经被重命名或删除,或者网络问题导致文件无法保存…” 的解决方案SharePoint 2013 App概述How to Shrink SharePoint Content Database Log File?Project Web App Feature无法开启的解决方案

文章评论
发表评论

热门文章 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”

最新文章 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件 如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database s

人气排行 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”SharePoint 2013 安装图解 SharePoint安装步骤图解教程SharePoint 如何开启访问请求[SharePoint入门教程]一SharePoint概述[SharePoint入门教程]一创建SharePoint母版页

盖楼回复X

(您的评论需要经过审核才能显示)