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

您的位置:欧非资源网 > 其他专区 > SharePoint > SharePoint Silverlight中如何使用Net客户端对象模型

SharePoint Silverlight中如何使用Net客户端对象模型

时间:2020-01-23 14:27作者:admin来源:未知人气:262我要评论(0)

1、创建Silverlight时,选择Silverlight 4,不要选择版本5,试了很久版本5都调用不了,自己也不知道什么原因,谷歌也没找到答案,后来尝试版本4,可以调用;

  至于Host the Silverlight application是否勾选没有影响;

clip_image002

  2、Silverlight中使用客户端脚本,和Net中不一样,要添加下面两个引用;

clip_image004

  3、两个需要的引用,在服务器上位置为C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15TEMPLATELAYOUTSClientBin,如下图:

clip_image006

  4、然后在Silverlight的cs文件中添加引用,如下:

  using Microsoft.SharePoint.Client;

  然后添加读取List的代码,如下:

复制代码
public string url = "http://server:80";
Web web;
List list;
ListItemCollection itemColl;
string listName = "Silverlight";
string camlStr = "";

private void btn_ShowMessage_Click(object sender, RoutedEventArgs e)
{
    getdata();
}

public void getdata()
{
    try
    {
        ClientContext context = new ClientContext(url);
        web = context.Web;
        list = web.Lists.GetByTitle(listName);
        CamlQuery query = new CamlQuery();
        query.ViewXml = camlStr;
        itemColl = list.GetItems(query);
        context.Load(itemColl);
        context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnSuccessed),
            new ClientRequestFailedEventHandler(OnFailed));
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

private void OnSuccessed(Object sender, ClientRequestSucceededEventArgs args)
{
    this.Dispatcher.BeginInvoke(LoadData);
}

private void LoadData()
{
    String data = string.Empty;
    foreach (ListItem item in itemColl)
    {
        data += item["Title"].ToString() + "rn";
    }
    lb_Message.Content = data;
}

private void OnFailed(Object sender, ClientRequestFailedEventArgs args)
{
    this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show("Get Data Failed"); });
}
复制代码

  5、前台页面添加Silverlight展示WebPart,添加完毕如下图:

clip_image008

  6、点击ShowMessage,执行客户端对象模型的方法,结果如下图:

clip_image010

总 结

  自己对于Silverlight不是很熟悉,只是小有了解SharePoint,所以有问题之处还请大家指正。尝试了很多次,才发现如何能在Silverlight中使用SharePoint客户端对象模型,希望分享给有需要的人,给大家一个参考吧。

  好了,就到这里,休息。。休息一下。。

相关阅读 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

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