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

  • 相关阅读:
    一题多解 —— 同时找到序列的最大值最小值
    中位数与顺序统计量
    软件开发 —— 极限编程(XP:Extreme Programming)
    一题多解 —— 二项式分布的期望和方差的计算
    C++中explicit关键字用法
    【联系】二项分布的对数似然函数与交叉熵(cross entropy)损失函数
    随机变量统计独立性的相关证明
    PowerShell管理SCOM_批量设置维护模式(下)
    导出AD用户所属组,查询AD用户(aduser)
    SQL脚本运行
  • 原文地址:https://www.cnblogs.com/Jayan/p/1787617.html
Copyright © 2011-2022 走看看