zoukankan      html  css  js  c++  java
  • SharePoint 2013 Silverlight中使用Netclient对象模型

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

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

    clip_image002

      2、Silverlight中使用client脚本,和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() + "
    ";
        }
        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,运行client对象模型的方法。结果例如以下图:

    clip_image010

    总 结

      自己对于Silverlight不是非常熟悉,仅仅是小有了解SharePoint,所以有问题之处还请大家指正。尝试了非常多次,才发现怎样能在Silverlight中使用SharePointclient对象模型,希望分享给有须要的人,给大家一个參考吧。

      好了,就到这里,歇息。

    。歇息一下。。

  • 相关阅读:
    android开发之重写Application类
    android开发之Parcelable使用详解
    android开发之Bundle使用
    android开发之gridlayout使用入门
    android开发之merge结合include优化布局
    android开发布局优化之ViewStub
    android开发之PreferenceScreen使用详解
    android开发之使用Messenger实现service与activity交互
    LeetCode All in One 题目讲解汇总(持续更新中...)
    JavaWeb知识点总结
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7150997.html
Copyright © 2011-2022 走看看