zoukankan      html  css  js  c++  java
  • Sharepoint2010应用开发四:使用客户对象模型(Client Object Model)向SharePoint列表写数据

    1、 打开VS2010File->New Project->WPF Application,确保选择.NET Framework3.5,为新项目命名,如:SPWriteListWPF

    2、 WPF设计面板添加4Label4textbox和三个按钮,如下图:

    3、 添加引用Microsoft.SharePoint.Client. dllMicrosoft.SharePoint.Client.Runtime.dll,在MainWindow.xaml.cs中添加如下using 语句:

     using ClientOM = Microsoft.SharePoint.Client;

    using Microsoft.SharePoint.Client;

     

    添加变量:

    string strSPURL = "";

           string strBlogTitle = "";

           string strBlogContent = "";

           string strBlogAuthor = "";

                   

                    在添加按钮的事件方法中添加如下代码:

    代码
    private void btnAdd_Click(object sender, RoutedEventArgs e)
            {
                strSPURL 
    = txtbxURL.Text;
                strBlogTitle 
    = txtbxBlogTitle.Text;
                strBlogContent 
    = txtbxBlogContent.Text;
                strBlogAuthor 
    = txtbxBlogAuthor.Text;
                ClientOM.ClientContext mySPContext 
    = new ClientContext(strSPURL);
                ClientOM.List productsList 
    = mySPContext.Web.Lists.GetByTitle("Blog");
                mySPContext.Load(mySPContext.Web);
                mySPContext.Load(productsList);
                mySPContext.ExecuteQuery();
                ListItemCreationInformation newBlogRecord 
    = new ListItemCreationInformation();
                ClientOM.ListItem newBlogItem 
    = productsList.AddItem(newBlogRecord);
                newBlogItem[
    "Title"= strBlogTitle;
                newBlogItem[
    "Content"= strBlogContent;
                newBlogItem[
    "Writer"= strBlogAuthor;
                newBlogItem.Update();
                mySPContext.ExecuteQuery();
            }

    在上面的代码中,我们没有使用CAML来把数据写到Sharepoint的列表中,这是因为在Sharepoint2010中,Sharepint会自动来创建CAML.

    4、 运行项目,填写一些数据,提交数据,你可以到你的Sharepoint列表中去查看刚刚添加的数据。

    项目文件:https://files.cnblogs.com/Jayan/SPWriteListWPF.zip

  • 相关阅读:
    mac的端口被占用
    php中的运算符、控制结构
    文档模式影响浏览器的渲染
    ubuntu 命令 tips 来自于 ubuntu中文论坛
    用好 Emacs 中的 register
    [转载] Rsync命令参数详解
    使用 python 遍历目录下的文件
    灵活的左移位( << )操作
    使用 iperf 测试两台机器间的最大带宽
    Emacs server 新启动方式 (仅在emacs daemon未启动时才启动daemon)
  • 原文地址:https://www.cnblogs.com/Jayan/p/1787617.html
Copyright © 2011-2022 走看看